class Emit::Process

Attributes

fiber[R]
return_value[R]
state[RW]

Public Class Methods

new(*args, **kwargs, &block) click to toggle source
# File lib/emit/process.rb, line 8
def initialize(*args, **kwargs, &block)
  fail ArgumentError.new("Must have a block as argument for Emit::Process.") unless block_given?
  @block        = block
  @args         = args
  @kwargs       = kwargs

  @state        = nil
  @executed     = false
  @return_value = nil

  @fiber        = nil
end

Public Instance Methods

*(number) click to toggle source
# File lib/emit/process.rb, line 68
def *(number)
  [*number.times.map { self.dup }]
end
active?() click to toggle source
# File lib/emit/process.rb, line 60
def active?
  @state == :active
end
executed?() click to toggle source
# File lib/emit/process.rb, line 64
def executed?
  @executed
end
notify(new_state) click to toggle source
# File lib/emit/process.rb, line 25
def notify(new_state)
  @state = new_state
  Scheduler.activate(self) unless Scheduler.current == self
end
run() click to toggle source
# File lib/emit/process.rb, line 38
def run
  @executed = false

  begin
    if @block.arity.negative?
      @return_value = @block.call(*@args, **@kwargs)
    elsif @block.arity > 0
      @return_value = @block.call(*@args)
    else
      @return_value = @block.call
    end
  rescue ::Emit::ChannelPoisonedException => e
    propagate_poison
    raise e
  rescue ::Emit::ChannelRetiredException => e
    propagate_retire
    raise e
  end

  @executed = true
end
start() click to toggle source
# File lib/emit/process.rb, line 30
def start
  @fiber = Fiber.new { run }
end
transfer() click to toggle source
# File lib/emit/process.rb, line 34
def transfer
  @fiber.transfer
end
wait() click to toggle source
# File lib/emit/process.rb, line 21
def wait
  Scheduler.get_next.transfer while active?
end

Private Instance Methods

propagate_poison() click to toggle source
# File lib/emit/process.rb, line 74
def propagate_poison
  @args.each do |arg|
    arg.poison if arg.methods.include?(:poison)
  end
end
propagate_retire() click to toggle source
# File lib/emit/process.rb, line 80
def propagate_retire
  @args.each do |arg|
    arg.retire if arg.methods.include?(:retire)
  end
end