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.4.tar.gz (12.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

simple_async_task-1.0.4-py3-none-any.whl (11.8 kB view details)

Uploaded Python 3

File details

Details for the file simple_async_task-1.0.4.tar.gz.

File metadata

  • Download URL: simple_async_task-1.0.4.tar.gz
  • Upload date:
  • Size: 12.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for simple_async_task-1.0.4.tar.gz
Algorithm Hash digest
SHA256 0c4d2540a7d310d1dcc59606ec86bcf6591ad12dc64984088aac09d1222fcb28
MD5 5b33f9c7427c0bcef5bd96ab8ec1b036
BLAKE2b-256 2a8d13c3497543dd65c3e84d809d1cf0f318a329ab2415d0eb00abfe0fd72b3c

See more details on using hashes here.

File details

Details for the file simple_async_task-1.0.4-py3-none-any.whl.

File metadata

File hashes

Hashes for simple_async_task-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 c7ab5fcc3af32150668c0dd42e9f6feb28b78502a9e6257d43ac10f0aec7c567
MD5 a3f6b16779202ad790489a77116e6526
BLAKE2b-256 c807239ba09ae1bba0b64c74d5ca88f45d51de58ba622faec631d0b194144596

See more details on using hashes here.

Supported by

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