Class: MrDarcy::Deferred

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/mr_darcy/deferred.rb

Overview

A wrapper around promises that can be externally resolved.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Deferred

Create a new deferred. Takes the following options:

  • driver: override the default driver for this promise.


27
28
29
30
31
# File 'lib/mr_darcy/deferred.rb', line 27

def initialize opts={}
  driver = opts[:driver] || MrDarcy.driver
  self.promise = MrDarcy::Promise.new(driver: driver) {}
  self.last_promise = promise
end

Instance Attribute Details

#last_promiseObject

Returns the value of attribute last_promise


11
12
13
# File 'lib/mr_darcy/deferred.rb', line 11

def last_promise
  @last_promise
end

#promiseObject

Returns the value of attribute promise


11
12
13
# File 'lib/mr_darcy/deferred.rb', line 11

def promise
  @promise
end

Instance Method Details

#fail(&block) ⇒ Object

See MrDarcy::Promise::Base#fail


19
20
21
# File 'lib/mr_darcy/deferred.rb', line 19

def fail &block
  self.last_promise = last_promise.fail(&block)
end

#then(&block) ⇒ Object

See MrDarcy::Promise::Base#then


14
15
16
# File 'lib/mr_darcy/deferred.rb', line 14

def then &block
  self.last_promise = last_promise.then(&block)
end