| Class | Rinda::NotifyTemplateEntry |
| In: |
lib/rinda/tuplespace.rb
|
| Parent: | TemplateEntry |
A NotifyTemplateEntry is returned by TupleSpace#notify and is notified of TupleSpace changes. You may receive either your subscribed event or the ‘close’ event when iterating over notifications.
See TupleSpace#notify_event for valid notification types.
ts = Rinda::TupleSpace.new
observer = ts.notify 'write', [nil]
Thread.start do
observer.each { |t| p t }
end
3.times { |i| ts.write [i] }
Outputs:
['write', [0]] ['write', [1]] ['write', [2]]
Creates a new NotifyTemplateEntry that watches place for +event+s that match tuple.
# File lib/rinda/tuplespace.rb, line 244
244: def initialize(place, event, tuple, expires=nil)
245: ary = [event, Rinda::Template.new(tuple)]
246: super(ary, expires)
247: @queue = Queue.new
248: @done = false
249: end
Yields event/tuple pairs until this NotifyTemplateEntry expires.
# File lib/rinda/tuplespace.rb, line 272
272: def each # :yields: event, tuple
273: while !@done
274: it = pop
275: yield(it)
276: end
277: rescue
278: ensure
279: cancel
280: end
Called by TupleSpace to notify this NotifyTemplateEntry of a new event.
# File lib/rinda/tuplespace.rb, line 254
254: def notify(ev)
255: @queue.push(ev)
256: end
Retrieves a notification. Raises RequestExpiredError when this NotifyTemplateEntry expires.
# File lib/rinda/tuplespace.rb, line 262
262: def pop
263: raise RequestExpiredError if @done
264: it = @queue.pop
265: @done = true if it[0] == 'close'
266: return it
267: end