Package afx :: Module pubsub :: Class fq
[hide private]
[frames] | no frames]

Class fq

source code

object --+
         |
        fq


I'm a simple round-robin fair queue. I'm like a regular channel, except
that when users L{put} an element into me, the element is associated with a
key (which represents an "input source"). When user later L{get} from me, I
pick elements from each of my keys in round-robin fashion, in the order in
which they were inserted. This way, each input source effectively gets its
own queue, and I can dequeue from the multiple input sources fairly.

q = fq( 10 )
yield q.put('user 1', 'packet 1')
yield q.put('user 1', 'packet 2')
yield q.put('user 1', 'packet 3')
yield q.put('user 2', 'packet 4')
yield q.put('user 2', 'packet 5')
yield q.put('user 2', 'packet 6')
while True:
    packet = yield q.get()
    yield send( packet ) # send packets 1, 4, 2, 5, 3, 6



Instance Methods [hide private]
 
__init__(self, n=0)
Initializer.
source code
 
_getq(self, k) source code
 
put(self, k, x) source code
 
get(self) source code

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

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, n=0)
(Constructor)

source code 
Initializer.
Parameters:
  • n (int) - maximum size of this queue, or None for infinite
Overrides: object.__init__

put(self, k, x)

source code 
Decorators:
  • @af.task

get(self)

source code 
Decorators:
  • @af.task