Class: EF::Thread

Inherits:
Thread
  • Object
show all
Defined in:
lib/event-framework.rb

Overview

provides threads with separated event loops

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args, &block) ⇒ Thread

creates a thread
parameters will be passed to the block



53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/event-framework.rb', line 53

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

Class Method Details

.instancesObject

returns instances of EF::Thread



46
47
48
# File 'lib/event-framework.rb', line 46

def self.instances
  ObjectSpace.each_object(self).to_a
end

Instance Method Details

#add(*args, &block) ⇒ Object

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



69
70
71
72
# File 'lib/event-framework.rb', line 69

def add(*args, &block)
  raise 'block not given' unless block_given?
  @queue << [args, block]
end