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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file simple-async-task-1.0.3.tar.gz
.
File metadata
- Download URL: simple-async-task-1.0.3.tar.gz
- Upload date:
- Size: 12.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0398b32019a65ed70a1abf3cf5742503764cb133238d94bc031ac14477aadebf |
|
MD5 | 28e70ce1a8503c025b235665a2fa772e |
|
BLAKE2b-256 | 982dc55f5e4a6e4a061889f68d7ccc2336928bc82b4119a33c1b0f0c6626971c |
File details
Details for the file simple_async_task-1.0.3-py3-none-any.whl
.
File metadata
- Download URL: simple_async_task-1.0.3-py3-none-any.whl
- Upload date:
- Size: 11.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d2dd6a123fd5d0569b51c48d0f9f6183658c1d126bdc4c56b346fddf121fe3c4 |
|
MD5 | aeabc33ca3352ba0e5f04faf9a1f3cb6 |
|
BLAKE2b-256 | 8c21ea06e22158fbaaa42a1e57cedc3ddf2d6f81b9a968c4e47638fb923501d2 |