httpx/lib/httpx.rb
HoneyryderChuck 27d81f3090 introduce custom timer to replace Timers::Group
The HTTPX::Timers class mimicks the same top-level API as its
predecessors, but simplifies its implementation. Adding a timer will
resort all timers, while lookups are roughly the same complexity. The
key difference is that callbacks are now aggregated by interval, i.e.
different requests setting the same timeout, will reuse the same timer.
This is a more simple design than Timers::Group, which stores timers in
a binary search tree; the latter will perform well in any environment,
whereas the first one is more tailored for the use-case of httpx, where
most of the times no timers will be set, and when they do, the same
timer will be reused for all requests because they usually have the same
set of options (and therefore timeouts).
2021-09-20 13:19:55 +01:00

67 lines
1.5 KiB
Ruby

# frozen_string_literal: true
require "httpx/version"
require "httpx/extensions"
require "httpx/errors"
require "httpx/utils"
require "httpx/punycode"
require "httpx/domain_name"
require "httpx/altsvc"
require "httpx/callbacks"
require "httpx/loggable"
require "httpx/registry"
require "httpx/transcoder"
require "httpx/timers"
require "httpx/pool"
require "httpx/headers"
require "httpx/request"
require "httpx/response"
require "httpx/options"
require "httpx/chainable"
require "mutex_m"
# Top-Level Namespace
#
module HTTPX
# All plugins should be stored under this module/namespace. Can register and load
# plugins.
#
module Plugins
@plugins = {}
@plugins.extend(Mutex_m)
# Loads a plugin based on a name. If the plugin hasn't been loaded, tries to load
# it from the load path under "httpx/plugins/" directory.
#
def self.load_plugin(name)
h = @plugins
unless (plugin = h.synchronize { h[name] })
require "httpx/plugins/#{name}"
raise "Plugin #{name} hasn't been registered" unless (plugin = h.synchronize { h[name] })
end
plugin
end
# Registers a plugin (+mod+) in the central store indexed by +name+.
#
def self.register_plugin(name, mod)
h = @plugins
h.synchronize { h[name] = mod }
end
end
# :nocov:
def self.const_missing(const_name)
super unless const_name == :Client
warn "DEPRECATION WARNING: the class #{self}::Client is deprecated. Use #{self}::Session instead."
Session
end
# :nocov:
extend Chainable
end
require "httpx/session"