Top Level Namespace

Includes:
Socket::Constants

Defined Under Namespace

Modules: Bellite Classes: Async, BelliteJsonRpc, BelliteJsonRpcApi, Future, Promise, PromiseApi

Instance Method Summary collapse

Instance Method Details

#deferredFuture

Creates Future object for JSON-RPC Server response

Returns:



659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
# File 'lib/bellite.rb', line 659

def deferred()
    cb = []
    answer = false

    future = false
    reject = false

    _then = lambda do |*args|
        success = args[0] || false
        failure = args[1] || false
        cb << [success,failure]
        if answer
            answer.call
        end
        return future.promise
    end

    resolve = lambda do |result|
        while cb.size > 0
            success, failure = cb.shift()
            begin
                if success != false
                    change, res = success.call(result)
                    if change and res===nil
                        result = res
                    end
                end
            rescue Exception => err
                if failure != false
                    res = failure.call(err)
                elsif cb.size = 0
                    #excepthook
                end
                return reject.call(res==nil ? err : res)
            end
        end
        answer = lambda { resolve.call(result) }
    end

    reject = lambda do |error|
        while cb.size > 0
            failure = cb.shift()[1]
            begin
                if failure != false
                    change, res = failure.call(error)
                    if change and res===nil
                        error = res
                    end
                end
            rescue Exception => err
                res = err
                if cb.size == 0
                    #excepthook
                end
            end
        end
        answer = lambda { reject.call(error) }
    end

    future = Future.new _then, resolve, reject
    return future
end