Sha256: 1b95c1519821fa7419321ab8c9070692e223416eba7dd44b4ba10c8c3c09c1e2

Contents?: true

Size: 758 Bytes

Versions: 2

Compression:

Stored size: 758 Bytes

Contents

# -*- coding: binary -*-
module Rex

###
#
# This class provides a wrapper around Thread.new that can provide
# additional features if a corresponding thread provider is set.
#
###

class ThreadFactory

	@@provider = nil

	def self.provider=(val)
		@@provider = val
	end

	def self.spawn(name, crit, *args, &block)
		if @@provider
			if block
				return @@provider.spawn(name, crit, *args){ |*args_copy| block.call(*args_copy) }
			else
				return @@provider.spawn(name, crit, *args)
			end
		else
			t = nil
			if block
				t = ::Thread.new(*args){ |*args_copy| block.call(*args_copy) }
			else
				t = ::Thread.new(*args)
			end
			t[:tm_name] = name
			t[:tm_crit] = crit
			t[:tm_time] = Time.now
			t[:tm_call] = caller
			return t
		end

	end
end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
librex-0.0.68 lib/rex/thread_factory.rb
librex-0.0.66 lib/rex/thread_factory.rb