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.
Пример
ts = Rinda::TupleSpace.new
observer = ts.notify 'write', [nil]
Thread.start do
observer.each { |t| p t }
end
3.times { |i| ts.write [i] }
Выходные данные:
['write', [0]] ['write', [1]] ['write', [2]]
Общедоступные методы класса
# File lib/rinda/tuplespace.rb, line 244 def initialize(place, event, tuple, expires=nil) ary = [event, Rinda::Template.new(tuple)] super(ary, expires) @queue = Thread::Queue.new @done = false end
Создает новый NotifyTemplateEntry, который отслеживает place события, соответствующие tuple.
Общедоступные методы экземпляра
# File lib/rinda/tuplespace.rb, line 272
def each # :yields: event, tuple
while !@done
it = pop
yield(it)
end
rescue
ensure
cancel
end Возвращает пары «событие/кортеж» до истечения срока действия этого NotifyTemplateEntry.
# File lib/rinda/tuplespace.rb, line 254 def notify(ev) @queue.push(ev) end
Вызывается TupleSpace для уведомления этого NotifyTemplateEntry о новом событии.
# File lib/rinda/tuplespace.rb, line 262 def pop raise RequestExpiredError if @done it = @queue.pop @done = true if it[0] == 'close' return it end
Извлекает уведомление. Вызывает RequestExpiredError, когда срок действия этого NotifyTemplateEntry истекает.
Ruby Core © 1993–2017 Yukihiro Matsumoto
Licensed under the Ruby License.
Ruby Standard Library © contributors
Licensed under their own licenses.