Ticket #54 (closed defect: fixed)

Opened 2 years ago

Last modified 2 years ago

add EM.fork

Reported by: tmm1 Assigned to: raggi
Priority: minor Milestone: EventMachine "Framework"
Keywords: Cc:

Description

def EM.fork &blk
  raise if reactor_running?
  fork do
    EM.run(&blk)
  end
end

Change History

07/19/08 01:51:24 changed by tmm1

def EM.fork &blk
  raise if reactor_running?

  unless @forks
    at_exit{
      @forks.each{ |pid| Process.kill('KILL', pid) }
    }
  end

  (@forks ||= []) << Kernel.fork do
    EM.run(&blk)
  end
end

07/20/08 07:30:55 changed by tmm1

Forking off another EM reactor is possible while a reactor is running, with the following steps:

Kernel.fork do
  # set a fork flag to true (useful for cleanup on exit)
  def EM.is_fork?() true end

  if EM.reactor_running?
    EM.stop_event_loop
    EM.release_machine  # EventMachine instance never gets released
  end

  # EM doesn't reset reactor_running
  def EM.reactor_running?
    @reactor_running = false
  end

  EM.run{
    EM.add_periodic_timer(1){ puts('hi') }
  }
end

07/22/08 12:06:37 changed by tmm1

  • status changed from new to closed.
  • resolution set to fixed.

EM.fork_reactor added in Changeset 739