Promises for Python
Yet another module for doing promises in python! This time with transparent proxies, and other convoluted stuff that will make you wish someone smarter had worked on this.
author: | Christopher O’Brien <obriencj@gmail.com> |
---|---|
license: | LGPL v.3 |
Attempts to deliver on a promise, and returns the resulting value. If the delivery of work causes an exception, it will be raised here.
Parameters: | on_promise : Proxy or Container promise
|
---|---|
Returns: | value :
|
Representation of a promise. If the promise is undelivered, will not deliver on it. If it is delivered, will deliver to check if the delivery indicates that the promise was broken.
Parameters: | of_promise : Proxy or Container
|
---|---|
Returns: | value : str
|
Attempts to deliver on a promise. If delivery raises an Exception, it is caught and the sys.exc_info() is stored into a BrokenPromise instance which is returned in lieu of a normal result.
This can be called on any Proxy or Container, not just those that were created as breakable via the breakable_lazy and breakable_proxy functions.
Using this function to deliver on a promise will not change the behavior of whether it is considered delivered or not when an Exception is raised.
Only subclasses of Exception are caught – BaseException instances are considered too important to be caught this way.
Parameters: | on_promise : Proxy or Container promise
|
---|---|
Returns: | value :
|
Bases: object
Result indicating a promise was broken. See the breakable_lazy, breakable_proxy, and breakable_deliver functions for more information.
Bases: exceptions.Exception
Raised when a paired promise’s delivery function is called more than once.
Bases: exceptions.Exception
Raised when attempting to deliver on a promise whose underlying delivery function hasn’t been called.
Creates a new container promise to find an answer for work.
Parameters: | work : callable
*args :
**kwds :
|
---|---|
Returns: | promise : Container
|
Creates a Container promise to perform work. If delivery of the work raises an Exception, a BrokenPromise instance is created to wrap the sys.exc_info() and is returned in lieu of a result.
Unlike a promise created by lazy_proxy, raising an Exception in the work will result in the promise being considered delivered, but broken. Further attempts at delivery will not re-execute the work, but will return the BrokenPromise instance from the first failure.
Returns a tuple of a new Container, a unary function to deliver a value into that promise, and a ternary function to feed an exception to the promise.
If blocking is True, then any attempt to deliver on the promise will block until/unless a value or exception has been set via the setter or seterr functions.
Returns: | promise : Container
setter : function(value)
seterr : function(exc_type, exc_inst, exc_tb)
|
---|
Examples
>>> prom, setter, seterr = promise()
>>> setter(5)
>>> deliver(prom)
5
Creates a new proxy promise to find an answer for work.
Parameters: | work : callable
*args :
**kwds :
|
---|---|
Returns: | promise : Proxy
|
Creates a Proxy promise to perform work. If delivery of the work raises an Exception, a BrokenPromise instance is created to wrap the sys.exc_info() and is returned in lieu of a result.
Unlike a promise created by lazy, raising an Exception in the work will result in the promise being considered delivered, but broken. Further attempts at delivery will not re-execute the work, but will return the BrokenPromise instance from the first failure.
Returns a tuple of a new Proxy, a unary function to deliver a value into that promise, and a ternary function to feed an exception to the promise.
If blocking is True, then any attempt to deliver on the promise (including accessing its members) will block until/unless a value or exception has been set via the setter or seterr functions.
Returns: | promise : Proxy
setter : function(value)
seterr : function(exc_type, exc_inst, exc_tb)
|
---|
Examples
>>> prom, setter, seterr = promise_proxy()
>>> setter(5)
>>> prom
5