Class: PG::EM::FeaturedDeferrable
- Inherits:
-
EM::DefaultDeferrable
- Object
- EM::DefaultDeferrable
- PG::EM::FeaturedDeferrable
- Defined in:
- lib/pg/em/featured_deferrable.rb
Overview
Deferrable with error protectors
- Author
-
Rafal Michalski
Instance Method Summary collapse
-
#bind_status(df) ⇒ Object
bind deferred status of this deferrable to other
df
. - #completion(&blk) ⇒ Object
-
#initialize(&blk) ⇒ FeaturedDeferrable
constructor
A new instance of FeaturedDeferrable.
- #protect(fail_value = nil) ⇒ Object
- #protect_and_succeed(fail_value = nil) ⇒ Object
Constructor Details
#initialize(&blk) ⇒ FeaturedDeferrable
Returns a new instance of FeaturedDeferrable.
9 10 11 |
# File 'lib/pg/em/featured_deferrable.rb', line 9 def initialize(&blk) completion(&blk) if block_given? end |
Instance Method Details
#bind_status(df) ⇒ Object
bind deferred status of this deferrable to other df
36 37 38 39 |
# File 'lib/pg/em/featured_deferrable.rb', line 36 def bind_status(df) df.callback { |*a| succeed(*a) } df.errback { |*a| fail(*a) } end |
#completion(&blk) ⇒ Object
13 14 15 16 |
# File 'lib/pg/em/featured_deferrable.rb', line 13 def completion(&blk) callback(&blk) errback(&blk) end |
#protect(fail_value = nil) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/pg/em/featured_deferrable.rb', line 18 def protect(fail_value = nil) yield rescue Exception => e ::EM.next_tick { fail e } fail_value end |
#protect_and_succeed(fail_value = nil) ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/pg/em/featured_deferrable.rb', line 25 def protect_and_succeed(fail_value = nil) ret = yield rescue Exception => e ::EM.next_tick { fail e } fail_value else ::EM.next_tick { succeed ret } ret end |