Class Rinda::NotifyTemplateEntry
In: 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.

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]]

Methods

each   new   notify   pop  

Public Class methods

Creates a new NotifyTemplateEntry that watches place for +event+s that match tuple.

[Source]

# File rinda/tuplespace.rb, line 244
    def initialize(place, event, tuple, expires=nil)
      ary = [event, Rinda::Template.new(tuple)]
      super(ary, expires)
      @queue = Queue.new
      @done = false
    end

Public Instance methods

Yields event/tuple pairs until this NotifyTemplateEntry expires.

[Source]

# File rinda/tuplespace.rb, line 272
    def each # :yields: event, tuple
      while !@done
        it = pop
        yield(it)
      end
    rescue 
    ensure
      cancel
    end

Called by TupleSpace to notify this NotifyTemplateEntry of a new event.

[Source]

# File rinda/tuplespace.rb, line 254
    def notify(ev)
      @queue.push(ev)
    end

Retrieves a notification. Raises RequestExpiredError when this NotifyTemplateEntry expires.

[Source]

# File rinda/tuplespace.rb, line 262
    def pop
      raise RequestExpiredError if @done
      it = @queue.pop
      @done = true if it[0] == 'close'
      return it
    end

[Validate]

ruby-doc.org is hosted and maintained by James Britt and Happy Camper Studios, a Ruby application development company in Phoenix, Arizona. The site was created in 2002 as part of the Ruby Documentation Project to promote the Ruby language and to help other Ruby hackers.

Documentation content on ruby-doc.org is provided by remarkable members of the Ruby community.

For more information on the Ruby programming language, visit ruby-lang.org.

Want to help improve Ruby's API docs? See Ruby Documentation Guidelines.