telegram.ext.utils.promise.Promise¶
-
class
telegram.ext.utils.promise.
Promise
(pooled_function, args, kwargs, update=None, error_handling=True)¶ Bases:
object
A simple Promise implementation for use with the run_async decorator, DelayQueue etc.
- Parameters
pooled_function (
callable
) – The callable that will be called concurrently.args (
list
|tuple
) – Positional arguments forpooled_function
.kwargs (
dict
) – Keyword arguments forpooled_function
.update (
telegram.Update
|object
, optional) – The update this promise is associated with.error_handling (
bool
, optional) – Whether exceptions raised byfunc
may be handled by error handlers. Defaults toTrue
.
-
pooled_function
¶ The callable that will be called concurrently.
- Type
callable
-
args
¶ Positional arguments for
pooled_function
.- Type
list
|tuple
-
kwargs
¶ Keyword arguments for
pooled_function
.- Type
dict
-
done
¶ Is set when the result is available.
- Type
threading.Event
-
update
¶ Optional. The update this promise is associated with.
- Type
telegram.Update
|object
-
error_handling
¶ Optional. Whether exceptions raised by
func
may be handled by error handlers. Defaults toTrue
.- Type
bool
-
add_done_callback
(callback)¶ Callback to be run when
telegram.ext.utils.promise.Promise
becomes done.Note
Callback won’t be called if
pooled_function
raises an exception.- Parameters
callback (
callable
) – The callable that will be called when promise is done.will be called by passing Promise.result() as only positional argument. (callback) –
-
property
exception
¶ The exception raised by
pooled_function
orNone
if no exception has been raised (yet).
-
result
(timeout=None)¶ Return the result of the
Promise
.- Parameters
timeout (
float
, optional) – Maximum time in seconds to wait for the result to be calculated.None
means indefinite. Default isNone
.- Returns
Returns the return value of
pooled_function
orNone
if thetimeout
expires.
:raises object exception raised by
pooled_function
.:
-
run
()¶ Calls the
pooled_function
callable.