Class: Minx::Scheduler
- Inherits:
-
Object
- Object
- Minx::Scheduler
- Defined in:
- lib/minx/scheduler.rb
Instance Method Summary (collapse)
- - (Object) enqueue(fiber)
-
- (Scheduler) initialize
constructor
A new instance of Scheduler.
- - (Object) main
- - (Object) switch(fiber)
- - (Object) yield
Constructor Details
- (Scheduler) initialize
A new instance of Scheduler
4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/minx/scheduler.rb', line 4 def initialize @queue = [] @main = Fiber.new do while true until @queue.empty? fiber = @queue.shift fiber.transfer if fiber.alive? end Fiber.yield end end end |
Instance Method Details
- (Object) enqueue(fiber)
37 38 39 |
# File 'lib/minx/scheduler.rb', line 37 def enqueue(fiber) @queue << fiber end |
- (Object) main
29 30 31 32 33 34 35 |
# File 'lib/minx/scheduler.rb', line 29 def main if Minx.root? @main.transfer else Fiber.yield end end |
- (Object) switch(fiber)
41 42 43 44 |
# File 'lib/minx/scheduler.rb', line 41 def switch(fiber) @queue << Fiber.current fiber.resume end |
- (Object) yield
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/minx/scheduler.rb', line 17 def yield if Minx.root? unless @queue.empty? fiber = @queue.shift fiber.transfer if fiber.alive? end else @queue << Fiber.current Fiber.yield end end |