Module: Fiber::Local
- Defined in:
- lib/fiber/local.rb,
lib/fiber/local/version.rb
Constant Summary collapse
- VERSION =
"0.1.0"
Instance Method Summary collapse
-
#instance ⇒ Object
Get the current thread-local instance.
-
#instance=(instance) ⇒ Object
Assigns to the fiber-local instance.
-
#local ⇒ Object
Instantiate a new thread-local object.
Instance Method Details
#instance ⇒ Object
Get the current thread-local instance. Create it if required.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/fiber/local.rb', line 36 def instance thread = Thread.current name = self.name if instance = thread[self.name] return instance end unless instance = thread.thread_variable_get(name) if instance = self.local thread.thread_variable_set(name, instance) end end thread[self.name] = instance return instance end |
#instance=(instance) ⇒ Object
Assigns to the fiber-local instance.
57 58 59 60 |
# File 'lib/fiber/local.rb', line 57 def instance= instance thread = Thread.current thread[self.name] = instance end |
#local ⇒ Object
Instantiate a new thread-local object. By default, invokes new to generate the instance.
30 31 32 |
# File 'lib/fiber/local.rb', line 30 def local self.new end |