Sha256: c3f3b570f95a05265cec067800f78c79ed883be2b9be7e7107565d3a3be22bbb

Contents?: true

Size: 1.01 KB

Versions: 17

Compression:

Stored size: 1.01 KB

Contents

# -*- coding: utf-8 -*-

module Handsoap
  class Deferred
    def initialize
      @callback = nil
      @callback_cache = nil
      @errback = nil
      @errback_cache = nil
    end
    def has_callback?
      !! @callback
    end
    def has_errback?
      !! @errback
    end
    def callback(&block)
      raise "Already assigned a block for callback" if @callback
      @callback = block
      if @callback_cache
        payload = @callback_cache
        trigger_callback(*payload)
      end
      self
    end
    def errback(&block)
      raise "Already assigned a block for errback" if @errback
      @errback = block
      if @errback_cache
        payload = @errback_cache
        trigger_errback(*payload)
      end
      self
    end
    def trigger_callback(*args)
      if @callback
        @callback.call(*args)
      else
        @callback_cache = args
      end
    end
    def trigger_errback(*args)
      if @errback
        @errback.call(*args)
      else
        @errback_cache = args
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 3 rubygems

Version Path
handsoap-1.4.0 lib/handsoap/deferred.rb
handsoap-1.3.0 lib/handsoap/deferred.rb
handsoap-1.2.2 lib/handsoap/deferred.rb
handsoap-1.1.8 lib/handsoap/deferred.rb
handsoap-1.1.7 lib/handsoap/deferred.rb
pgericson-handsoap-1.1.10 lib/handsoap/deferred.rb
pgericson-handsoap-1.1.9 lib/handsoap/deferred.rb
pgericson-handsoap-1.1.8 lib/handsoap/deferred.rb
pgericson-handsoap-1.1.7 lib/handsoap/deferred.rb
handsoap-1.1.6 lib/handsoap/deferred.rb
handsoap-1.1.5 lib/handsoap/deferred.rb
whenyouneedme-handsoap-1.1.4 lib/handsoap/deferred.rb
handsoap-1.1.4 lib/handsoap/deferred.rb
handsoap-1.1.3 lib/handsoap/deferred.rb
handsoap-1.1.2 lib/handsoap/deferred.rb
handsoap-1.1.1 lib/handsoap/deferred.rb
handsoap-1.1.0 lib/handsoap/deferred.rb