Class: Fiber
- Inherits:
-
Object
- Object
- Fiber
- Defined in:
- lib/fibre/core_ext/fiber.rb
Class Method Summary collapse
- .await(*a, &b) ⇒ Object
- .await_only {|Fiber.current| ... } ⇒ Object
- .scope(*a, &b) ⇒ 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
.await(*a, &b) ⇒ Object
39 40 41 |
# File 'lib/fibre/core_ext/fiber.rb', line 39 def await(*a, &b) Fibre::Scope.in_scope? ? Fibre::Scope.await(*a, &b) : await_only(*a, &b) end |
.await_only {|Fiber.current| ... } ⇒ Object
50 51 52 53 |
# File 'lib/fibre/core_ext/fiber.rb', line 50 def await_only yield(Fiber.current) if block_given? Fiber.yield! end |
.scope(*a, &b) ⇒ Object
35 36 37 |
# File 'lib/fibre/core_ext/fiber.rb', line 35 def scope(*a, &b) Fibre::Scope.scope(*a, &b) end |
.yield! ⇒ Object
raise exception if we catch exception
44 45 46 47 48 |
# File 'lib/fibre/core_ext/fiber.rb', line 44 def yield! Fiber.yield.tap do |y| raise y if y.is_a?(Exception) end end |
Instance Method Details
#[](key) ⇒ Object
21 22 23 |
# File 'lib/fibre/core_ext/fiber.rb', line 21 def [](key) attributes[key] end |
#[]=(key, value) ⇒ Object
25 26 27 |
# File 'lib/fibre/core_ext/fiber.rb', line 25 def []=(key,value) attributes[key] = value end |
#attributes ⇒ Object
13 14 15 |
# File 'lib/fibre/core_ext/fiber.rb', line 13 def attributes @attributes ||= {} end |
#leave(exception, message = nil) ⇒ Object
29 30 31 |
# File 'lib/fibre/core_ext/fiber.rb', line 29 def leave(exception, =nil) resume exception.is_a?(Class) ? exception.new() : exception end |
#root? ⇒ Boolean
17 18 19 |
# File 'lib/fibre/core_ext/fiber.rb', line 17 def root? self.eql? Fibre.root end |