rsb.patterns.future¶
Contains an implementation of the future pattern.
Code author: jmoringe
Classes
A |
|
|
Represents the results of in-progress operations. |
Exceptions
|
|
|
|
|
-
exception
rsb.patterns.future.
FutureError
(*args)¶ Bases:
RuntimeError
-
with_traceback
()¶ Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
-
args
¶
-
-
exception
rsb.patterns.future.
FutureExecutionError
(*args)¶ Bases:
rsb.patterns.future.FutureError
-
with_traceback
()¶ Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
-
args
¶
-
-
exception
rsb.patterns.future.
FutureTimeout
(*args)¶ Bases:
rsb.patterns.future.FutureError
-
with_traceback
()¶ Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
-
args
¶
-
-
class
rsb.patterns.future.
DataFuture
¶ Bases:
rsb.patterns.future.Future
A
Future
that automatically returns the payload of anEvent
.Instances of this class are like ordinary
Future`s, the only difference being that the :obj:`get
method returns the payload of anEvent
object.Code author: jmoringe
Create a new
Future
object.-
get
(timeout=0)¶ Try to obtain and return the result of the represented operation.
If necessary, wait for the operation to complete, and then retrieve its result.
- Parameters
timeout – The amount of time in seconds in which the operation has to complete.
- Type timeout
float, optional
- Returns
The result of the operation if it did complete successfully.
- Raises FutureExecutionException
If the operation represented by the Future object failed.
- Raises FutureTimeoutException
If the result does not become available within the amount of time specified via
timeout
.
-
set_error
(message)¶ Indicate a failure and notify all waiting consumers.
Mark the operation represented by the
Future
object as failed, setmessage
as the error message and notify all threads waiting for the result.- Parameters
message – An error message that explains why/how the operation failed.
- Type message
str
-
set_result
(result)¶ Set the result and notify all waiting consumers.
Sets the result of the
Future
toresult
and wakes all threads waiting for the result.- Parameters
result – The result of the
Future
object.
-
property
done
¶ Check whether the represented operation is still in progress.
- Returns
True
is the represented operation finished successfully or failed.- Rtype
bool
-
-
class
rsb.patterns.future.
Future
¶ Bases:
object
Represents 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.-
get
(timeout=0)¶ Try to obtain and return the result of the represented operation.
If necessary, wait for the operation to complete, and then retrieve its result.
- Parameters
timeout – The amount of time in seconds in which the operation has to complete.
- Type timeout
float, optional
- Returns
The result of the operation if it did complete successfully.
- Raises FutureExecutionException
If the operation represented by the Future object failed.
- Raises FutureTimeoutException
If the result does not become available within the amount of time specified via
timeout
.
-
set_error
(message)¶ Indicate a failure and notify all waiting consumers.
Mark the operation represented by the
Future
object as failed, setmessage
as the error message and notify all threads waiting for the result.- Parameters
message – An error message that explains why/how the operation failed.
- Type message
str
-
set_result
(result)¶ Set the result and notify all waiting consumers.
Sets the result of the
Future
toresult
and wakes all threads waiting for the result.- Parameters
result – The result of the
Future
object.
-
property
done
¶ Check whether the represented operation is still in progress.
- Returns
True
is the represented operation finished successfully or failed.- Rtype
bool
-