Module: TIMEx
- Extended by:
- TIMEx
- Included in:
- TIMEx
- Defined in:
- lib/timex.rb,
lib/timex/clock.rb,
lib/timex/result.rb,
lib/timex/expired.rb,
lib/timex/version.rb,
lib/timex/deadline.rb,
lib/timex/registry.rb,
lib/timex/telemetry.rb,
lib/timex/auto_check.rb,
lib/timex/on_timeout.rb,
lib/timex/configuration.rb,
lib/timex/strategies/io.rb,
lib/timex/composers/base.rb,
lib/timex/named_component.rb,
lib/timex/strategies/base.rb,
lib/timex/composers/hedged.rb,
lib/timex/timeout_handling.rb,
lib/timex/strategies/ractor.rb,
lib/timex/strategies/unsafe.rb,
lib/timex/strategies/wakeup.rb,
lib/timex/cancellation_token.rb,
lib/timex/composers/adaptive.rb,
lib/timex/telemetry/adapters.rb,
lib/timex/test/virtual_clock.rb,
lib/timex/composers/two_phase.rb,
lib/timex/strategies/closeable.rb,
lib/timex/strategies/subprocess.rb,
lib/timex/strategies/cooperative.rb,
lib/timex/propagation/http_header.rb,
lib/timex/propagation/rack_middleware.rb
Defined Under Namespace
Modules: AutoCheck, Clock, Composers, NamedComponent, Propagation, Registry, Strategies, Telemetry, Test, TimeoutHandling Classes: CancellationToken, Configuration, Deadline, Expired, Result, TimeoutError
Constant Summary collapse
- Error =
Class.new(StandardError)
- ConfigurationError =
Class.new(Error)
- StrategyNotFoundError =
Class.new(Error)
- VERSION =
Gem version. Bumped on release; mirrored in the gemspec.
"0.1.0"- ON_TIMEOUT_SYMBOLS =
Canonical set of symbol modes accepted by
on_timeout:on #deadline and related APIs, plus Configuration#default_on_timeout=.Kept in one place so validation, documentation, and TimeoutHandling stay aligned.
%i[raise raise_standard return_nil result].freeze
Class Method Summary collapse
-
.configuration ⇒ Configuration
(also: config)
Returns the process-wide Configuration, constructing it once under
CONFIG_MUTEX. -
.configure {|draft| ... } ⇒ Object
Yields a duplicated Configuration, then atomically publishes it when the outermost block completes without raising.
-
.reset_configuration! ⇒ void
Replaces the configuration with a fresh Configuration under the mutex.
Instance Method Summary collapse
-
#call(deadline_or_seconds, strategy: nil, auto_check: nil, on_timeout: nil, **opts) {|deadline| ... } ⇒ Object
(also: #deadline)
Primary entrypoint: runs
blockunderdeadline_or_secondsusing the resolved strategy.
Class Method Details
.configuration ⇒ Configuration Also known as: config
Returns the process-wide Configuration, constructing it once under CONFIG_MUTEX.
125 126 127 |
# File 'lib/timex/configuration.rb', line 125 def configuration @configuration || CONFIG_MUTEX.synchronize { @configuration ||= Configuration.new } end |
.configure {|draft| ... } ⇒ Object
Yields a duplicated Configuration, then atomically publishes it when the outermost block completes without raising.
Nested configure calls mutate the same draft and only the outermost swap commits, keeping re-entrant initialization safe.
139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/timex/configuration.rb', line 139 def configure raise ArgumentError, "TIMEx.configure requires a block" unless block_given? CONFIG_MUTEX.synchronize do outer = @configure_draft.nil? @configure_draft ||= configuration.dup begin yield @configure_draft @configuration = @configure_draft if outer ensure @configure_draft = nil if outer end end end |
.reset_configuration! ⇒ void
This method returns an undefined value.
Replaces the configuration with a fresh Configuration under the mutex.
157 158 159 |
# File 'lib/timex/configuration.rb', line 157 def reset_configuration! CONFIG_MUTEX.synchronize { @configuration = Configuration.new } end |
Instance Method Details
#call(deadline_or_seconds, strategy: nil, auto_check: nil, on_timeout: nil, **opts) {|deadline| ... } ⇒ Object Also known as: deadline
Primary entrypoint: runs block under deadline_or_seconds using the resolved strategy.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/timex.rb', line 21 def call(deadline_or_seconds, strategy: nil, auto_check: nil, on_timeout: nil, **opts, &block) raise ArgumentError, "block required" unless block deadline = Deadline.coerce(deadline_or_seconds) strategy = Registry.resolve_for_call(strategy) cfg = config on_timeout ||= cfg.default_on_timeout auto_check = cfg.auto_check_default if auto_check.nil? runner = if auto_check ->(d) { TIMEx::AutoCheck.run(d) { yield(d) } } else block end strategy.call( deadline:, on_timeout:, **opts, &runner ) end |