telegram.utils.promise.Promise

class telegram.utils.promise.Promise(pooled_function, args, kwargs)

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 for pooled_function.
  • kwargs (dict) – Keyword arguments for pooled_function.
pooled_function

callable – The callable that will be called concurrently.

args

list | tuple – Positional arguments for pooled_function.

kwargs

dict – Keyword arguments for pooled_function.

done

threading.Event – Is set when the result is available.

exception

The exception raised by pooled_function or None 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 is None.
Returns:Returns the return value of pooled_function or None if the timeout expires.
Raises:Any exception raised by pooled_function.
run()

Calls the pooled_function callable.