Class: EF::Thread
- Inherits:
-
Thread
- Object
- Thread
- EF::Thread
- Defined in:
- lib/event-framework.rb
Overview
provides threads with separated event loops
Class Method Summary collapse
-
.instances ⇒ Object
returns instances of EF::Thread.
Instance Method Summary collapse
-
#add(*args, &block) ⇒ Object
adds a task which will be executed in the event loop
parameters will be passed to the block. -
#initialize(*args, &block) ⇒ Thread
constructor
creates a thread
parameters will be passed to the block.
Constructor Details
#initialize(*args, &block) ⇒ Thread
creates a thread
parameters will be passed to the block
59 60 61 62 63 64 65 66 67 68 69 70 |
# 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 |
Class Method Details
.instances ⇒ Object
returns instances of EF::Thread
52 53 54 |
# File 'lib/event-framework.rb', line 52 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
75 76 77 78 |
# File 'lib/event-framework.rb', line 75 def add(*args, &block) raise 'block not given' unless block_given? @queue << [args, block] end |