Class Spring
In: lib/spring.rb
Parent: Object

Methods

empty?   get   length   new   num_collecter   sign_up   size  

Included Modules

Observable

Constants

GET = :get
SIGN_UP = :sign_up

Public Class methods

[Source]

# File lib/spring.rb, line 20
  def initialize(*items)
    @q = *items
    @mutex = Mutex.new
    @collecter = []
  end

Public Instance methods

[Source]

# File lib/spring.rb, line 42
  def empty?
    @mutex.synchronize { return @q.empty? }
  end

[Source]

# File lib/spring.rb, line 26
  def get(collecter_id)
    @mutex.synchronize do
      if @collecter.include?(collecter_id)
        item = @q.shift
        changed(true)
        notify_observers(self.object_id, GET, collecter_id)
        return item
      end
    end
  end
length()

Alias for size

[Source]

# File lib/spring.rb, line 57
  def num_collecter
    @mutex.synchronize { @collecter.length }
  end

[Source]

# File lib/spring.rb, line 46
  def sign_up(collecter_id)
    @mutex.synchronize do
      unless @collecter.include?(collecter_id)
        @collecter << collecter_id
        changed(true)
        notify_observers(self.object_id, SIGN_UP, collecter_id)
        return nil
      end
    end
  end

[Source]

# File lib/spring.rb, line 37
  def size
    @mutex.synchronize { return @q.size }
  end

[Validate]