Teek::BackgroundWork Class
Unified background work API. Delegates to a mode-specific implementation
selected via the mode: parameter.
Modes:
- :thread — traditional threading; best for I/O-bound work where the GVL
is released during blocking calls. Always available.
- :ractor — true parallel execution via Ractor (Ruby 4.x+ only); best
for CPU-bound work.
Inherits: Object
Class Methods ↑
background_mode_class(name)
@api private
background_modes
@api private
register_background_mode(name, klass)
@api private
Instance Methods ↑
done?
Returns Boolean
initialize(app, data, mode: :thread, worker: nil, &block)
Parameters
appTeek::App— the application instancedataObject— data passed to the worker blockmodeSymbol—:threador:ractorworkerClass, nil— optional worker class (must respond to#call(task, data))
Returns BackgroundWork — a new instance of BackgroundWork
@raise ArgumentError if mode is unknown
@yield task, data block executed in the background
@yieldparam task BackgroundThread::BackgroundWork::TaskContext, BackgroundRactor4x::BackgroundWork::TaskContext
@yieldparam data Object
mode
Returns Symbol — the active mode (:thread or :ractor)
paused?
Returns Boolean
send_message(msg)
Send a message to the worker.
Parameters
msgObject— any value (must be Ractor-shareable in:ractormode)
Returns self
Attributes ↑
abort_on_error [R]
Returns Boolean — when true, raise on ractor errors instead of warning
(default false)
drop_intermediate [R]
Returns Boolean — when true, only the latest progress value per poll
cycle is delivered (default true)
poll_ms [R]
Returns Integer — UI poll interval in milliseconds (default 16)
name [R]
Returns String, nil — optional name for this task