pub struct Builder { /* private fields */ }Expand description
Thread factory mirroring std::thread::Builder, with app binding (ADR-314).
Same knobs as the std builder — Builder::name and Builder::stack_size
— plus the host bind/unbind around the closure. Use this when an app needs
a named long-lived thread or a smaller stack (for example 512 KiB on a Pi
Zero 2 W); use spawn when the defaults are enough.
§Examples
use node_app_sdk_rust::thread::Builder;
let handle = Builder::new()
.name("worker".into())
.stack_size(512 * 1024)
.spawn(|| 6 * 7)
.unwrap();
assert_eq!(handle.join().unwrap(), 42);Implementations§
Source§impl Builder
impl Builder
Sourcepub fn new() -> Self
pub fn new() -> Self
Same defaults as std::thread::Builder::new.
Sourcepub fn name(self, name: String) -> Self
pub fn name(self, name: String) -> Self
Sets the name of the thread for debugging and panic messages.
Sourcepub fn stack_size(self, size: usize) -> Self
pub fn stack_size(self, size: usize) -> Self
Sets the size of the stack (in bytes) for the new thread.
Sourcepub fn spawn<F, T>(self, f: F) -> Result<JoinHandle<T>>
pub fn spawn<F, T>(self, f: F) -> Result<JoinHandle<T>>
Spawns an OS thread that is bound to this app (ADR-314).
Everything std::thread::Builder::spawn does, plus the binding: the
host charges the new thread’s CPU and the memory it allocates to this
app from the moment it starts until it exits. The binding is released
when the closure returns — including when it panics, and including when
the OS refuses to start the thread (then there is nothing to release).
A host that predates ADR-314 exports no hooks: the closure still runs and nothing else happens.
§Errors
The OS could not create a thread; the closure never runs.