Class: Innate::State::Fiber
- Inherits:
-
Object
- Object
- Innate::State::Fiber
- Defined in:
- lib/innate/state/fiber.rb
Overview
Our accessor to the currently active Fiber, an instance of Innate::State::Fiber will be assigned to Innate::STATE if fibers are available.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #defer ⇒ Object
-
#sync ⇒ Object
In an environment where only Fiber is used there is no concurrency, so we don’t have to lock with a Mutex.
-
#wrap(&block) ⇒ Object
We don’t use Fiber in a concurrent manner and they don’t run concurrently by themselves, so we directly #resume the Fiber to get the return value of
block.
Instance Method Details
#[](key) ⇒ Object
42 43 44 |
# File 'lib/innate/state/fiber.rb', line 42 def [](key) ::Fiber.current[key] end |
#[]=(key, value) ⇒ Object
46 47 48 |
# File 'lib/innate/state/fiber.rb', line 46 def []=(key, value) ::Fiber.current[key] = value end |
#defer ⇒ Object
65 66 67 68 69 70 71 |
# File 'lib/innate/state/fiber.rb', line 65 def defer a = Innate::Fiber.current ::Thread.new do b = Innate::Fiber.new{ a.keys.each{|k| b[k] = a[k] }; yield } b.resume end end |
#sync ⇒ Object
In an environment where only Fiber is used there is no concurrency, so we don’t have to lock with a Mutex.
61 62 63 |
# File 'lib/innate/state/fiber.rb', line 61 def sync yield end |
#wrap(&block) ⇒ Object
We don’t use Fiber in a concurrent manner and they don’t run concurrently by themselves, so we directly #resume the Fiber to get the return value of block.
54 55 56 |
# File 'lib/innate/state/fiber.rb', line 54 def wrap(&block) Innate::Fiber.new(&block).resume end |