Skip to main content

Implementing Javascript-like async Promise in Python for Eventlet-based coroutines.

Project description

Eventlet Promise

This package implements a Javascript-like Promise to use for eventlet threads.

from typing import Callable

import eventlet as hub
from eventlet_promise.promise import Promise

def executor_(resolveFunc : Callable[[Any], None], rejectFunc : Callable[[Any], None]):
        t1, t2 = 5, 6
        # print(t1 := 10 * random())
        hub.spawn_after(t1, lambda: print('\tResolving') or resolveFunc(t1))
        hub.spawn_after(t2, lambda: print('\tRejecting') or rejectFunc(TimeoutError("Timed out")))

# promise = Promise(None)
promise = Promise(executor_)
new_promise = promise.then()
attached = Promise.resolve(new_promise).then(lambda x: x + 1).then(lambda x: x + 1)
p1 = Promise.resolve(1).then(2).then()
p2 = Promise.reject(1).then(2, 2).then().then()
p3 = p1.then()
p_all = Promise.all([p1, p3, new_promise, promise])
p_settled = Promise.allSettled([p1, p2, p3, new_promise, promise])
p_any = Promise.any([p2, promise.then(), new_promise, promise])
p_race = Promise.race([new_promise.then(), new_promise.then()])

while True:
    print(promise)
    print(new_promise)
    print(attached)
    print(p1)
    print(p2)
    print(p3)
    print('all', p_all)
    print('allSettled', p_settled)
    print('any', p_any)
    print('race', p_race)

    hub.sleep(0)	# to allow other eventlet coroutines to work.
    hub.sleep(2)	# so that you don't see all scroll by.

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

eventlet_promise-0.5.1.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

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

eventlet_promise-0.5.1-py3-none-any.whl (11.1 kB view details)

Uploaded Python 3

File details

Details for the file eventlet_promise-0.5.1.tar.gz.

File metadata

  • Download URL: eventlet_promise-0.5.1.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.10

File hashes

Hashes for eventlet_promise-0.5.1.tar.gz
Algorithm Hash digest
SHA256 ad8c482885c821bdf94f76c2e7c127433dd5581d03f41798eca30959bb83f658
MD5 72204f863c8d13875949f96cd0363487
BLAKE2b-256 c800d324d9a2abfd859f3e2ea0c64f01e0064543f909032fc4a718ada1fa960d

See more details on using hashes here.

File details

Details for the file eventlet_promise-0.5.1-py3-none-any.whl.

File metadata

File hashes

Hashes for eventlet_promise-0.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 23ca4dbe113998dd0934e6a17ad49eabf4a7de9d51de8b7319ac37fe0620ae62
MD5 c649b57aa4ef261cc8e20367bc5d8f5c
BLAKE2b-256 466e5670af74d976b77b8a78b6b239a2602c7c0d792ce9b542315f7410f168d4

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