Module: DeferrableGratification::Fluent

Defined in:
lib/deferrable_gratification/fluent.rb

Overview

Allows JQuery-style fluent syntax for registering several callbacks and errbacks on the same Deferrable. e.g.

    DeferrableMonkeyShaver.new(monkey).
      callback { puts "Monkey is shaved" }.
      callback { monkey.entertain! }.
      errback {|e| puts "Unable to shave monkey! #{e}" }.
      errback {|_| monkey.terminate! }.
      shave

Include this into a class that has already included Deferrable.

Instance Method Summary (collapse)

Instance Method Details

- (Deferrable, Fluent) callback(&block)

Register block to be called on success.

Returns:

  • (Deferrable, Fluent)

    self

See Also:

  • EventMachine::Deferrable#callback


19
20
21
22
# File 'lib/deferrable_gratification/fluent.rb', line 19

def callback(&block)
  super(&block)
  self
end

- (Deferrable, Fluent) errback(&block)

Register block to be called on failure.

Returns:

  • (Deferrable, Fluent)

    self

See Also:

  • EventMachine::Deferrable#errback


29
30
31
32
# File 'lib/deferrable_gratification/fluent.rb', line 29

def errback(&block)
  super(&block)
  self
end

- (Deferrable, Fluent) timeout(seconds)

Ensure that if this Deferrable doesn’t either succeed or fail within the timeout, it will call its errback with no parameters.

Returns:

  • (Deferrable, Fluent)

    self

See Also:

  • EventMachine::Deferrable#timeout


40
41
42
43
# File 'lib/deferrable_gratification/fluent.rb', line 40

def timeout(seconds)
  super(seconds)
  self
end