Skip to main content

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


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)

Uploaded Source

Built Distribution

async_helper-0.0.3-py3-none-any.whl (3.6 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