Class: Rinda::NotifyTemplateEntry (Ruby 2.3.7)
Description: Class : Rinda::NotifyTemplateEntry - Ruby 2.3.7

- Home
- Core 2.3.7
- Std-lib 2.3.7
- Downloads

Support for the Ruby 2.3 series has ended. See here for reference.

### Home Classes Methods

### In Files

- rinda/tuplespace.rb

### Parent

Rinda::TemplateEntry

### Methods

- ::new
- #each
- #notify
- #pop

### Class/Module Index

Quicksearch

- Rinda
- Rinda::DRbObjectTemplate
- Rinda::InvalidHashTupleKey
- Rinda::NotifyTemplateEntry
- Rinda::RequestCanceledError
- Rinda::RequestExpiredError
- Rinda::RindaError
- Rinda::RingFinger
- Rinda::RingProvider
- Rinda::RingServer
- Rinda::SimpleRenewer
- Rinda::Template
- Rinda::TemplateEntry
- Rinda::Tuple
- Rinda::TupleBag
- Rinda::TupleBag::TupleBin
- Rinda::TupleEntry
- Rinda::TupleSpace
- Rinda::TupleSpaceProxy
- Rinda::WaitTemplateEntry

No matching classes.

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

new(place, event, tuple, expires=nil) click to toggle source

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

                   # File rinda/tuplespace.rb, line 245
    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

each() click to toggle source

Yields event/tuple pairs until this NotifyTemplateEntry expires.

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

notify(ev) click to toggle source

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

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

pop() click to toggle source

Retrieves a notification. Raises RequestExpiredError when this NotifyTemplateEntry expires.

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