Skip to main content

A simple library for managing asynchrony.

Project description

Async Task

A simple library for managing asynchrony; inspired by Microsoft's Task Class.

Motivation

async_task provides an equally accessible syntax to the async and await keywords, but with simpler usage semantics, particularly when calling asynchronous code from within synchronous code.

Usage

Import the Async class from async_tasks and use as a wrapper for callable objects to execute them asynchronously, or apply as a decorator to permanently transform a function or method into an Async object.

Invoke Async instances as any other callable. The return of the call will be an Async.Worker instance. Workers have a wait method and a result property; when either of these are called, the caller will synchronize with the background worker, blocking until completion or timeout.
e.g.:

from async_task import Async

@Async
def func():
    return 0

worker = func()
worker.wait(1) 
assert worker.result == 0
# it is not necessary to call wait() prior to accessing result, however, it is not possible to provide a timeout with 
# result.
from async_task import Async

def func():
    return 0

async_obj = Async(func)
worker = async_obj() 
assert func() == worker.result
from async_task import Async

class Cls:
    def __init__(self, attr):
        self.attr = attr
    @Async
    def func(self):
        return self.attr

assert Cls(0).func().result == 0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

simple-async-task-1.0.3.tar.gz (12.0 kB view hashes)

Uploaded Source

Built Distribution

simple_async_task-1.0.3-py3-none-any.whl (11.8 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page