class BackPressure::Executor

Implementations of `BackPressure::Executor` are capable of providing blocking back-pressure to callers using their `execute` or `execute!` methods.

This interface makes no guarantees about how implementations go about controlling back-pressure or the order in which execution will occur in the presence or absence of blocking back-pressure.

@abstract

@author Ry Biesemeyer <identity@yaauue.com> @since 1.0.0

Public Instance Methods

blocked?() click to toggle source

Helper method for determining if any threads are currently blocked by back-pressure.

@api observation @note This method should be used only for observation-based tooling.

@return [Boolean]

# File lib/back_pressure/executor.rb, line 93
def blocked?
  fail NotImplementedError
end
blocked_threads() click to toggle source

Helper method for observing which threads, if any, are blocked at the instant the method is invoked. The returned value is a frozen snapshot, and the included threads are not guaranteed to be still blocking by the time they are accessed.

@api observation @note This method should be used only for observation-based tooling.

@return [Set{Thread}]

# File lib/back_pressure/executor.rb, line 81
def blocked_threads
  fail NotImplementedError
end
execute(blocking_time_limit: nil) click to toggle source

Executes the provided block, after waiting out any back-pressure, returning `true` IFF the block was executed.

@param blocking_time_limit [Number]: the maximum time to wait, in

seconds, when back-pressure is
being applied, before aborting
(optional).

@return [Boolean]: returns `true` if block was successfully executed,

and `false` if tht `blocking_time_limit` was
reached before it could be executed.

@yieldreturn [void]: the value returned by the block is ignored by

this method.
# File lib/back_pressure/executor.rb, line 48
def execute(blocking_time_limit: nil)
  fail NotImplementedError
end
execute!(blocking_time_limit: nil) click to toggle source

Executes the provided block, after waiting out any back-pressure, returning the result of the block or raising an `ExecutionExpired` exception if the provided limit was reached before execution could begin.

@param blocking_time_limit [Number]: the maximum time to wait, in

seconds, when back-pressure is
being applied, before aborting
(optional).

@return [Object]: returns the unmodified value of the result of

executing the provided block.

@raise [ExecutionExpired] @yieldreturn [Object]: the value returned from the block is returned

by this method
# File lib/back_pressure/executor.rb, line 67
def execute!(blocking_time_limit: nil)
  fail NotImplementedError
end