Module: Teek::BackgroundThread
- Defined in:
- lib/teek/background_thread.rb
Overview
Thread-based background work for Teek applications. Always available, works on all Ruby versions.
Best for I/O-bound work (network, file downloads, database queries) where the worker releases the GVL during blocking calls, allowing real concurrency with the UI thread. For CPU-bound work, the GVL serializes execution and thread overhead makes this slower than synchronous mode. Use :ractor for CPU-bound parallelism (Ruby 4.x+).
Defined Under Namespace
Classes: BackgroundWork
Constant Summary collapse
- PAUSED_POLL_MS =
High-level API for background work with messaging support.
Example:
task = Teek::BackgroundThread::BackgroundWork.new(app, data) do |t| data.each do |item| break if t. == :stop t.yield(process(item)) end end.on_progress { |r| update_ui(r) } .on_done { puts "Done!" } task.(:pause) task.(:resume) task.stopPoll interval when paused (slower to save CPU)
10000