Skip to content

Extension to Python's Future (Promise) API that allows chaining using .then() (like JavaScript Promises)

License

Notifications You must be signed in to change notification settings

dvdotsenko/python-future-then

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WHAT & WHY

Extending Python's concurrent.futures.Future (Promise) object with missing chaining API like .then().

While Futures (aka Promises) are formally specified and available as part of Python as of v 3.2+, and is available as backported module for Python versions v.2.x, standard implementation is lacking any formal or convenient API for the most frequent use of Promises - chaining.

JavaScript Promises/A+ API have then-ability as part of the spec. This project takes standard concurrent.futures.Future Python class and extends it with borrowed .then() behavior from JavaScript Promises.

INSTALL

pip install futures_then

USE

In [1]: from futures_then import ThenableFuture as Future

In [2]: f1 = Future()

In [3]: f2 = f1.then(lambda v: v + ' transformed')

In [4]: f1.set_result('future')

In [5]: f2.result()
Out[5]: 'future transformed'

About

Extension to Python's Future (Promise) API that allows chaining using .then() (like JavaScript Promises)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages