~singpolyma/em_fiberscheduler

e279be1d034adff9e43523e8f452efadf2955686 — Stephen Paul Weber 4 months ago dabf158
Allow disabling/changing autostart/autostop behaviour
1 files changed, 6 insertions(+), 5 deletions(-)

M lib/em_fiberscheduler.rb
M lib/em_fiberscheduler.rb => lib/em_fiberscheduler.rb +6 -5
@@ 16,9 16,10 @@ module EventMachine
	end

	class FiberScheduler
		def initialize
		def initialize(autostart: true)
			@count = 0
			@timeouts = {}
			@autostart = autostart
		end

		def run


@@ 29,14 30,14 @@ module EventMachine
				EM.instance_variable_set(:@reactor_running, false)
			end)

			tick
			autostop
			EM.run
		end

		def tick
		def autostop
			EM.next_tick do
				if @count.positive? || EM.work_left?
					tick
					autostop
				else
					EM.stop
				end


@@ 44,7 45,7 @@ module EventMachine
		end

		def close
			run
			run if @autostart
		end

		def fiber(&block)