class Rinda::NotifyTemplateEntry
A NotifyTemplateEntry is returned by Rinda::TupleSpace#notify and is notified of TupleSpace changes. You may receive either your subscribed event or the 'close' event when iterating over notifications.
See Rinda::TupleSpace#notify_event for valid notification types.
Example
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]]
Public Class Methods
# File lib/rinda/tuplespace.rb, line 246 def initialize(place, event, tuple, expires=nil) ary = [event, Rinda::Template.new(tuple)] super(ary, expires) @queue = Queue.new @done = false end
Creates a new NotifyTemplateEntry that watches place
for +event+s that match tuple
.
Calls superclass method Rinda::TupleEntry.new
Public Instance Methods
# File lib/rinda/tuplespace.rb, line 274 def each # :yields: event, tuple while !@done it = pop yield(it) end rescue ensure cancel end
Yields event/tuple pairs until this NotifyTemplateEntry expires.
# File lib/rinda/tuplespace.rb, line 256 def notify(ev) @queue.push(ev) end
Called by TupleSpace to notify this NotifyTemplateEntry of a new event.
# File lib/rinda/tuplespace.rb, line 264 def pop raise RequestExpiredError if @done it = @queue.pop @done = true if it[0] == 'close' return it end
Retrieves a notification. Raises RequestExpiredError when this NotifyTemplateEntry expires.
Ruby Core © 1993–2017 Yukihiro Matsumoto
Licensed under the Ruby License.
Ruby Standard Library © contributors
Licensed under their own licenses.