class EF::Thread

provides threads with separated event loops

Public Class Methods

instances() click to toggle source

returns instances of EF::Thread

# File lib/event-framework.rb, line 52
def self.instances
  ObjectSpace.each_object(self).to_a
end
new(*args, &block) click to toggle source

creates a thread
parameters will be passed to the block

Calls superclass method
# File lib/event-framework.rb, line 59
def initialize(*args, &block)
  @queue = Queue.new

  super do
    block.call *args if block_given?

    while true
      args, block = @queue.pop
      block.call *args
    end
  end
end

Public Instance Methods

add(*args, &block) click to toggle source

adds a task which will be executed in the event loop
parameters will be passed to the block

# File lib/event-framework.rb, line 75
def add(*args, &block)
  raise 'block not given' unless block_given?
  @queue << [args, block]
end