pub struct EncoderWorker { /* private fields */ }Expand description
A persistent worker thread that executes submitted closures sequentially
(in submission order). Designed for command-buffer encoding workloads
where the cost of std::thread::spawn per task would dwarf the work.
The worker is single-threaded; submissions execute one-at-a-time. For parallelism with the main thread, the typical pattern is:
- Spawn one
EncoderWorkerat process start. - Per token: submit half the encoding work to the worker, encode the other half on the main thread, wait for both to complete.
EncoderWorker is NOT a thread pool — for that, spawn multiple workers.
Implementations§
Source§impl EncoderWorker
impl EncoderWorker
Sourcepub fn spawn() -> Self
pub fn spawn() -> Self
Spawn a new persistent worker thread. The thread runs until either
Self::shutdown is called or the EncoderWorker is dropped.
The worker’s run-loop blocks on the channel; CPU usage is zero when idle.
Sourcepub fn submit<F>(&self, f: F) -> Result<(), &'static str>
pub fn submit<F>(&self, f: F) -> Result<(), &'static str>
Submit a closure for execution on the worker thread. Returns immediately; the closure runs asynchronously.
To wait for the closure to complete, the caller must arrange its own
signaling (e.g., a (tx, rx) channel pair captured by the closure).
§Errors
Returns Err if the worker thread has been shut down or has panicked.