Sha256: 767dcc582b2f35701526db4de4232f74eb58618301d1f6c46545878d5902052d

Contents?: true

Size: 629 Bytes

Versions: 10

Compression:

Stored size: 629 Bytes

Contents

# frozen_string_literal: true

module HTTPX
  module Callbacks
    def on(type, &action)
      callbacks(type) << action
    end

    def once(event, &block)
      on(event) do |*args, &callback|
        block.call(*args, &callback)
        :delete
      end
    end

    def emit(type, *args)
      callbacks(type).delete_if { |pr| pr[*args] == :delete }
    end

    protected

    def inherit_callbacks(callbackable)
      @callbacks = callbackable.callbacks
    end

    def callbacks(type = nil)
      return @callbacks unless type
      @callbacks ||= Hash.new { |h, k| h[k] = [] }
      @callbacks[type]
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
httpx-0.3.1 lib/httpx/callbacks.rb
httpx-0.3.0 lib/httpx/callbacks.rb
httpx-0.2.1 lib/httpx/callbacks.rb
httpx-0.2.0 lib/httpx/callbacks.rb
httpx-0.1.0 lib/httpx/callbacks.rb
httpx-0.0.5 lib/httpx/callbacks.rb
httpx-0.0.4 lib/httpx/callbacks.rb
httpx-0.0.3 lib/httpx/callbacks.rb
httpx-0.0.2 lib/httpx/callbacks.rb
httpx-0.0.1 lib/httpx/callbacks.rb