class Goru::Scheduler

public

Public Class Methods

new(...) click to toggle source
Calls superclass method
# File lib/goru/scheduler.rb, line 16
def initialize(...)
  super

  @stopping = false
  @routines = Queue.new
  @condition = new_cond

  @reactors = 10.times.map {
    Reactor.new(queue: @routines, scheduler: self)
  }

  @threads = @reactors.map { |reactor|
    Thread.new {
      Thread.handle_interrupt(Interrupt => :never) do
        reactor.run
      end
    }
  }
end

Public Instance Methods

go(state = nil, io: nil, intent: :rw, &block) click to toggle source
public
# File lib/goru/scheduler.rb, line 38
def go(state = nil, io: nil, intent: :rw, &block)
  @routines << if io
    Routines::IO.new(state, io: io, intent: intent, &block)
  else
    Routine.new(state, &block)
  end
end
signal(reactor) click to toggle source
public
# File lib/goru/scheduler.rb, line 69
def signal(reactor)
  synchronize do
    if @reactors.all? { |reactor| reactor.status == :looking || reactor.status == :stopped }
      @stopping = true
    end

    @condition.signal
  end
end
stop() click to toggle source
public
# File lib/goru/scheduler.rb, line 60
def stop
  @stopping = true
  @routines.close
  @reactors.each(&:stop)
  @threads.each(&:join)
end
wait() click to toggle source
public
# File lib/goru/scheduler.rb, line 48
def wait
  synchronize do
    @condition.wait_until do
      @stopping
    end
  end
ensure
  stop
end