Class: Fiber
- Inherits:
-
Object
- Object
- Fiber
- Defined in:
- lib/fibre/core_ext/fiber.rb
Overview
Fiber.sync do |fiber|
fiber.resume response
fiber.leave StandardError, "Something"
end
Class Method Summary collapse
- .scope(*a, &b) ⇒ Object
- .sync(*a, &b) ⇒ Object
- .wait {|Fiber.current| ... } ⇒ Object
-
.yield! ⇒ Object
raise exception if we catch exception.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #attributes ⇒ Object
- #leave(exception, message = nil) ⇒ Object
- #root? ⇒ Boolean
Class Method Details
.scope(*a, &b) ⇒ Object
28 29 30 |
# File 'lib/fibre/core_ext/fiber.rb', line 28 def scope(*a, &b) Fibre::Scope.scope(*a, &b) end |
.sync(*a, &b) ⇒ Object
32 33 34 |
# File 'lib/fibre/core_ext/fiber.rb', line 32 def sync(*a, &b) Fibre::Scope.scope? ? Fibre::Scope.sync(*a, &b) : wait(*a, &b) end |
.wait {|Fiber.current| ... } ⇒ Object
43 44 45 46 |
# File 'lib/fibre/core_ext/fiber.rb', line 43 def wait yield(Fiber.current) if block_given? Fiber.yield! end |
.yield! ⇒ Object
raise exception if we catch exception
37 38 39 40 41 |
# File 'lib/fibre/core_ext/fiber.rb', line 37 def yield! Fiber.yield.tap do |y| raise y if y.is_a?(Exception) end end |
Instance Method Details
#[](key) ⇒ Object
18 19 20 |
# File 'lib/fibre/core_ext/fiber.rb', line 18 def [](key) attributes[key] end |
#[]=(key, value) ⇒ Object
22 23 24 |
# File 'lib/fibre/core_ext/fiber.rb', line 22 def []=(key,value) attributes[key] = value end |
#attributes ⇒ Object
10 11 12 |
# File 'lib/fibre/core_ext/fiber.rb', line 10 def attributes @attributes ||= {} end |
#leave(exception, message = nil) ⇒ Object
49 50 51 |
# File 'lib/fibre/core_ext/fiber.rb', line 49 def leave(exception, =nil) resume exception.is_a?(Class) ? exception.new() : exception end |