Class: Future

Inherits:
PromiseApi show all
Defined in:
lib/bellite.rb

Overview

Implements Future

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from PromiseApi

#always, #done, #fail, #then

Constructor Details

#initialize(_then, resolve = false, reject = false) ⇒ Future

Constructing object with then, success and failure functions

Parameters:

  • _then (Proc, lambda)

    Then-function

  • resolve (Proc, lambda) (defaults to: false)

    Success-function

  • reject (Proc, lambda) (defaults to: false)

    Failure-function



620
621
622
623
624
625
626
627
628
# File 'lib/bellite.rb', line 620

def initialize(_then, resolve=false, reject=false)
    @promise = Promise.new _then
    if resolve
        @resolve = resolve
    end
    if reject
        @reject = reject
    end
end

Instance Attribute Details

#promisePromise (readonly)

Promise object of this Future

Returns:



648
649
650
# File 'lib/bellite.rb', line 648

def promise
    @promise
end

#rejectProc, lambda (readonly)

Failure-function

Returns:

  • (Proc, lambda)


641
642
643
# File 'lib/bellite.rb', line 641

def reject(err)
    @reject.call(err)
end

#resolveProc, lambda (readonly)

Success-function

Returns:

  • (Proc, lambda)


634
635
636
# File 'lib/bellite.rb', line 634

def resolve(res=true)
    @resolve.call(res)
end

Instance Method Details

#then_(success = false, failure = false) ⇒ Object



652
653
654
# File 'lib/bellite.rb', line 652

def then_(success=false, failure=false)
    return @promise.then_(success, failure)
end