A bridge between the asynchronous and synchronous world
Project description
async-helper
async-helper by Sebastian Steins
Licence: MIT
Usage
import time, random
from async_helper import first_parallel_result
def time_consuming_function(i):
print("I consume a lot of time")
time.sleep(random.randint(1, 10))
return i
candidates = [
lambda: time_consuming_function(1),
lambda: time_consuming_function(2),
]
best_effort_result = first_parallel_result(candidates)
print(best_effort_result)
Giving preference
import time, random
from async_helper import first_parallel_result
def time_consuming_function(i):
print("I consume a lot of time")
time.sleep(random.randint(1, 10))
return i
candidates = [
0, lambda: time_consuming_function(1), # This callable will start immediately.
1, lambda: time_consuming_function(2), # This callable will start with `1` sec delay.
]
best_effort_result = first_parallel_result(candidates)
print(best_effort_result)
© 2021 Sebastian Steins
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
async-helper-0.0.3.tar.gz
(2.6 kB
view hashes)
Built Distribution
Close
Hashes for async_helper-0.0.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 638469c575e04dffd83f377cbdd1c45a1bf862009c193e7ab46d00f55e52fb31 |
|
MD5 | 286aac74f5092f2a433ceacf03cc4f50 |
|
BLAKE2b-256 | f769cf308429934e1ec1a2e9657762eb80d460c11c767986eaadb0db6b9792d7 |