Package viff :: Module runtime :: Class ShareList
[hide private]
[frames] | no frames]

Class ShareList

source code

Create a share that waits on a number of other shares.

Roughly modelled after the Twisted DeferredList class. The advantage of this class is that it is a Share (not just a Deferred) and that it can be made to trigger when a certain threshold of the shares are ready. This example shows how the pprint callback is triggered when a and c are ready:

>>> from pprint import pprint
>>> from viff.field import GF256
>>> a = Share(None, GF256)
>>> b = Share(None, GF256)
>>> c = Share(None, GF256)
>>> shares = ShareList([a, b, c], threshold=2)
>>> shares.addCallback(pprint)           # doctest: +ELLIPSIS
<ShareList at 0x...>
>>> a.callback(10)
>>> c.callback(20)
[(True, 10), None, (True, 20)]

The pprint function is called with a list of pairs. The first component of each pair is a boolean indicating if the callback or errback method was called on the corresponding Share, and the second component is the value given to the callback/errback.

If a threshold less than the full number of shares is used, some of the pairs may be missing and None is used instead. In the example above the b share arrived later than a and c, and so the list contains a None on its place.

Instance Methods [hide private]
__init__(self, shares, threshold=None)
Initialize a share list.
source code
_callback_fired(self, result, index, success) source code

Inherited from Share: __add__, __del__, __eq__, __ge__, __gt__, __le__, __lt__, __mul__, __neq__, __pow__, __radd__, __rmul__, __rsub__, __rxor__, __sub__, __xor__, clone, label, old_init

Inherited from twisted.internet.defer.Deferred: __repr__, __str__, addBoth, addCallback, addCallbacks, addErrback, callback, chainDeferred, errback, pause, setTimeout, unpause

Inherited from twisted.internet.defer.Deferred (private): _continue, _runCallbacks, _startRunCallbacks

Class Variables [hide private]

Inherited from twisted.internet.defer.Deferred: called, debug, paused, timeoutCall

Inherited from twisted.internet.defer.Deferred (private): _debugInfo

Method Details [hide private]

__init__(self, shares, threshold=None)

source code 

Initialize a share list.

The list of shares must be non-empty and if a threshold is given, it must hold that 0 < threshold <= len(shares). The default threshold is len(shares).

Overrides: twisted.internet.defer.Deferred.__init__