telegram.utils.promise.Promise

class telegram.utils.promise.Promise(pooled_function: Callable[[], RT], args: Union[List, Tuple], kwargs: Dict[str, Any], update: Union[str, Update] = None, error_handling: bool = 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 for pooled_function.

  • kwargs (dict) – Keyword arguments for pooled_function.

  • update (telegram.Update, optional) – The update this promise is associated with.

  • error_handling (bool, optional) – Whether exceptions raised by func may be handled by error handlers. Defaults to True.

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

error_handling

Optional. Whether exceptions raised by func may be handled by error handlers. Defaults to True.

Type

bool

property exception

The exception raised by pooled_function or None if no exception has been raised (yet).

result(timeout: float = None) → Optional[RT]

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() → None

Calls the pooled_function callable.