Sha256: c64481928036ed4f11d869e3b771b1f2f943fcd9186b51bae3eb4ded0bfc85e8

Contents?: true

Size: 620 Bytes

Versions: 5

Compression:

Stored size: 620 Bytes

Contents

module Plezi
	module EventMachine

		# A single worker.
		class Worker
			def initialize
				@stop = false
				wait = Worker.get_wait
				@thread = Thread.new { EventMachine.run wait until @stop }
			end
			def stop
				@stop = true
			end
			def join
				stop
				@thread.join rescue true
			end
			def alive?
				@thread.alive?
			end
			def status
				@thread.status
			end
			def self.get_wait
				@primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37] 
				@instances ||= -1
				@instances += 1 if @instances < 7
				@primes[@instances] / 10.0
			end
			def self.reset_wait
				@instances = -1
			end
		end
	end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
plezi-0.8.5 lib/plezi/eventmachine/workers.rb
plezi-0.8.4 lib/plezi/eventmachine/workers.rb
plezi-0.8.3 lib/plezi/eventmachine/workers.rb
plezi-0.8.2 lib/plezi/eventmachine/workers.rb
plezi-0.8.1 lib/plezi/eventmachine/workers.rb