Package pike :: Module model :: Class Future
[hide private]
[frames] | no frames]

Class Future

source code

object --+
         |
        Future

Result of an asynchronous operation.

Futures represent the result of an operation that has not yet completed. In Pike, they are most commonly used to track SMB2 request/response pairs, but they can be used for any asynchronous operation.

The result of a future can be waited for synchronously by simply calling Future.result, or a notification callback can be set with Future.then.

Futures implement the context manager interface so that they can be used as the context for a with block. If an exception is raised from the block, it will automatically be set as the result of the future.

Instance Methods [hide private]
 
__init__(self, request=None)
Initialize future.
source code
 
complete(self, response, traceback=None)
Completes the future with the given result.
source code
 
interim(self, response)
Set interim response.
source code
 
wait(self, timeout=30)
Wait for future result to become available.
source code
 
wait_interim(self, timeout=30)
Wait for interim response or actual result to become available.
source code
 
result(self, timeout=30)
Return result of future.
source code
 
then(self, notify)
Set notification function.
source code
 
__enter__(self) source code
 
__exit__(self, exc_type, exc_value, traceback) source code
 
__call__(self, *params, **kwparams) source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Instance Variables [hide private]
  interim_response
The interim response, usually an SMB2 response frame.
  request
The request associated with the future, usually an SMB2 request frame.
  response
The result of the future, usually an SMB2 response frame.
  traceback
The traceback of an exception result, if applicable.
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, request=None)
(Constructor)

source code 

Initialize future.

Parameters:
  • request - The request associated with the response.
Overrides: object.__init__

complete(self, response, traceback=None)

source code 

Completes the future with the given result.

Calling a future as a function is equivalent to calling this method.

Parameters:
  • response - The result of the future.
  • traceback - If response is an exception, an optional traceback

interim(self, response)

source code 

Set interim response.

Parameters:
  • response - The interim response.

wait(self, timeout=30)

source code 

Wait for future result to become available.

Parameters:
  • timeout - The time in seconds before giving up and raising TimeoutError

wait_interim(self, timeout=30)

source code 

Wait for interim response or actual result to become available.

Parameters:
  • timeout - The time in seconds before giving up and raising TimeoutError

result(self, timeout=30)

source code 

Return result of future.

If the result is not yet available, this function will wait for it. If the result is an exception, this function will raise it instead of returning it.

Parameters:
  • timeout - The time in seconds before giving up and raising TimeoutError

then(self, notify)

source code 

Set notification function.

Parameters:
  • notify - A function which will be invoked with this future as a parameter when its result becomes available. If it is already available, it will be called immediately.