Teek::BackgroundRactor4x::BackgroundWork Class
Ractor-based background work using Ruby 4.x Ractor::Port for streaming and Ractor.shareable_proc for blocks.
Inherits: Object
Instance Methods ↑
done?
Returns Boolean — whether the worker has finished
initialize(app, data, worker: nil, &block)
Parameters
appTeek::App— the application instance (forafterscheduling)dataObject— data passed to the worker block/classworkerClass, nil— optional worker class (must respond to#call(task, data))
Returns BackgroundWork — a new instance of BackgroundWork
@yield task, data block executed inside a Ractor
@yieldparam task TaskContext context for yielding results and checking messages
@yieldparam data Object the data passed to the constructor
on_done(&block)
Register a callback for when the worker finishes. Auto-starts the task if not already started.
Returns self
@yield called on the main thread when the worker completes
on_message(&block)
Register a callback for custom messages sent by the worker via
TaskContext#send_message.
Returns self
@yield msg called on the main thread with the message
on_progress(&block)
Register a callback for progress updates from the worker. Auto-starts the task if not already started.
Returns self
@yield value called on the main thread each time the worker yields a result
pause
Pause the worker. The worker will block on the next TaskContext#yield
or TaskContext#check_pause until #resume is called.
Returns self
paused?
Returns Boolean — whether the worker is paused
send_message(msg)
Send a message to the worker. The worker can receive it via
TaskContext#check_message or TaskContext#wait_message.
Messages are queued if the worker’s control port isn’t ready yet.
Parameters
msgObject— any Ractor-shareable value
Returns self
start
Explicitly start the background work. Called automatically by
#on_progress and #on_done; only needed when using #on_message
alone.
Returns self
stop
Request the worker to stop. Raises StopIteration inside the worker
on the next TaskContext#check_message or TaskContext#yield.
Returns self