Class: PromiseApi Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/bellite.rb

Overview

This class is abstract.

Promise API

Direct Known Subclasses

Future, Promise

Instance Method Summary collapse

Instance Method Details

#always(fn = nil, &blk) ⇒ Object

Runs then-function call with same function for success and failure

Parameters:

  • fn (Proc) (defaults to: nil)

    Function to handle success or failure

Returns:

  • Result of then-function call



568
569
570
# File 'lib/bellite.rb', line 568

def always(fn=nil, &blk)
    return then_(fn||blk, fn||blk)
end

#done(success, &blk) ⇒ Object

Runs then-function in case of success

Parameters:

  • success (Proc)

    Success handler

Returns:

  • Result of then-function call



582
583
584
# File 'lib/bellite.rb', line 582

def done(success, &blk)
    return then_(success||blk,false)
end

#fail(failure, &blk) ⇒ Object

Runs then-function in case of failure

Parameters:

  • failure (Proc)

    Failure handler

Returns:

  • Result of then-function call



575
576
577
# File 'lib/bellite.rb', line 575

def fail(failure, &blk)
    return then_(false, failure||blk)
end

#then(success = false, failure = false, &blk) ⇒ Object



586
587
588
# File 'lib/bellite.rb', line 586

def then(success=false, failure=false, &blk)
    return then_(success, failure, &blk)
end

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



589
590
591
592
593
594
# File 'lib/bellite.rb', line 589

def then_(success=false, failure=false, &blk)
    if (blk && (success || failure))
        raise ArgumentError, "Ambiguous block argument"
    end
    return @_then.call(success,failure)
end