rsb.patterns.future

Contains an implementation of the future pattern.

Code author: jmoringe

Classes

DataFuture() Instances of this class are like ordinary Future`s, the only difference being that the :obj:`get method returns the payload of an Event object.
Future() Objects of this class represent the results of in-progress operations.

Exceptions

FutureError(*args)
FutureExecutionError(*args)
FutureTimeout(*args)
exception rsb.patterns.future.FutureError(*args)

Bases: exceptions.RuntimeError

args
message
exception rsb.patterns.future.FutureExecutionError(*args)

Bases: rsb.patterns.future.FutureError

args
message
exception rsb.patterns.future.FutureTimeout(*args)

Bases: rsb.patterns.future.FutureError

args
message
class rsb.patterns.future.DataFuture

Bases: rsb.patterns.future.Future

Instances of this class are like ordinary Future`s, the only difference being that the :obj:`get method returns the payload of an Event object.

Code author: jmoringe

Create a new Future object that represents an in-progress operation for which a result is not yet available.

get(timeout=0)
isDone()

Check whether the represented operation is still in progress.

Returns:True is the represented operation finished successfully or failed.
Return type:bool
set(result)

Set the result of the Future to result and wake all threads waiting for the result.

Parameters:result – The result of the Future object.
setError(message)

Mark the operation represented by the Future object as failed, set message as the error message and notify all threads waiting for the result.

Parameters:message (str) – An error message that explains why/how the operation failed.
done

Check whether the represented operation is still in progress.

Returns:True is the represented operation finished successfully or failed.
Return type:bool
class rsb.patterns.future.Future

Bases: object

Objects of this class represent the results of in-progress operations.

Methods of this class allow checking the state of the represented operation, waiting for the operation to finish and retrieving the result of the operation.

Code author: jmoringe

Create a new Future object that represents an in-progress operation for which a result is not yet available.

get(timeout=0)

Try to obtain and then return the result of the represented operation.

If necessary, wait for the operation to complete, and then retrieve its result.

Parameters:

timeout (float, optional) – The amount of time in seconds in which the operation has to complete.

Returns:

The result of the operation if it did complete successfully.

Raises:
  • FutureExecutionException – If the operation represented by the Future object failed.
  • FutureTimeoutException – If the result does not become available within the amount of time specified via timeout.
isDone()

Check whether the represented operation is still in progress.

Returns:True is the represented operation finished successfully or failed.
Return type:bool
set(result)

Set the result of the Future to result and wake all threads waiting for the result.

Parameters:result – The result of the Future object.
setError(message)

Mark the operation represented by the Future object as failed, set message as the error message and notify all threads waiting for the result.

Parameters:message (str) – An error message that explains why/how the operation failed.
done

Check whether the represented operation is still in progress.

Returns:True is the represented operation finished successfully or failed.
Return type:bool