Class: Dry::Effects::Frame Private
- Inherits:
-
Object
- Object
- Dry::Effects::Frame
- Extended by:
- Initializer
- Defined in:
- lib/dry/effects/frame.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Stack frame
Instance Attribute Summary collapse
-
#provider ⇒ Provider
Effects provider.
Class Method Summary collapse
-
.spawn_fiber(stack) ⇒ Object
private
Spawn a new fiber with a stack of effect handlers.
-
.stack ⇒ Stack
private
Accessing current stack of effect handlers.
- .stack=(stack) ⇒ Object private
Instance Method Summary collapse
-
#call(*args, &block) ⇒ Object
private
Add new handler to the current stack and run the given block.
Methods included from Initializer
Instance Attribute Details
#provider ⇒ Provider
Returns Effects provider.
70 |
# File 'lib/dry/effects/frame.rb', line 70 param :provider |
Class Method Details
.spawn_fiber(stack) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Spawn a new fiber with a stack of effect handlers
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/dry/effects/frame.rb', line 31 def spawn_fiber(stack) fiber = ::Fiber.new do self.stack = stack yield end result = fiber.resume loop do error = false break result unless fiber.alive? provided = stack.(result) do ::Dry::Effects.yield(result) do |_, e| error = true e end end result = if error raise_in_fiber(fiber, provided) else fiber.resume(provided) end end end |
.stack ⇒ Stack
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Accessing current stack of effect handlers. It is inherently thread/fiber-local.
17 18 19 |
# File 'lib/dry/effects/frame.rb', line 17 def stack ::Thread.current[:dry_effects_stack] ||= Stack.new end |
.stack=(stack) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
23 24 25 |
# File 'lib/dry/effects/frame.rb', line 23 def stack=(stack) ::Thread.current[:dry_effects_stack] = stack end |
Instance Method Details
#call(*args, &block) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Add new handler to the current stack and run the given block
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/dry/effects/frame.rb', line 78 def call(*args, &block) stack = Frame.stack prov = provider.dup was_empty = stack.empty? prov.(*args) do if was_empty stack.push(prov) do Frame.spawn_fiber(stack, &block) end else stack.push(prov, &block) end end end |