Struct wasm_thread::Builder
source · pub struct Builder { /* private fields */ }
Expand description
Thread factory, which can be used in order to configure the properties of a new thread.
Implementations§
source§impl Builder
impl Builder
sourcepub fn spawn_scoped<'scope, 'env, F, T>(
self,
scope: &'scope Scope<'scope, 'env>,
f: F
) -> Result<ScopedJoinHandle<'scope, T>>
pub fn spawn_scoped<'scope, 'env, F, T>( self, scope: &'scope Scope<'scope, 'env>, f: F ) -> Result<ScopedJoinHandle<'scope, T>>
Spawns a new scoped thread using the settings set through this Builder
.
Unlike Scope::spawn, this method yields an std::io::Result to capture any failure to create the thread at the OS level.
source§impl Builder
impl Builder
sourcepub fn new() -> Builder
pub fn new() -> Builder
Creates a builder inheriting global configuration options set by Self::set_default.
sourcepub fn empty() -> Builder
pub fn empty() -> Builder
Creates a builder without inheriting global options set by Self::set_default.
sourcepub fn set_default(self)
pub fn set_default(self)
Sets current values as global default for all new builders created with Builder::new or Builder::default.
pub fn worker_script_url(self, worker_script_url: String) -> Builder
sourcepub fn name(self, name: String) -> Builder
pub fn name(self, name: String) -> Builder
Sets the name of the thread.
If not set, the default name is autogenerated.
sourcepub fn stack_size(self, size: usize) -> Builder
pub fn stack_size(self, size: usize) -> Builder
Sets the size of the stack (in bytes) for the new thread.
§Warning
This is currently not supported by wasm, but provided for API consistency with std::thread.
sourcepub fn wasm_bindgen_shim_url(self, url: String) -> Builder
pub fn wasm_bindgen_shim_url(self, url: String) -> Builder
Sets the URL of wasm_bindgen generated shim script.
sourcepub fn spawn<F, T>(self, f: F) -> Result<JoinHandle<T>>
pub fn spawn<F, T>(self, f: F) -> Result<JoinHandle<T>>
Spawns a new thread by taking ownership of the Builder
, and returns an
std::io::Result to its JoinHandle
.
sourcepub unsafe fn spawn_unchecked<'a, F, T>(self, f: F) -> Result<JoinHandle<T>>
pub unsafe fn spawn_unchecked<'a, F, T>(self, f: F) -> Result<JoinHandle<T>>
Spawns a new thread without any lifetime restrictions by taking ownership
of the Builder
, and returns an std::io::Result to its JoinHandle
.
§Safety
The caller has to ensure that no references in the supplied thread closure or its return type can outlive the spawned thread’s lifetime. This can be guaranteed in two ways:
- ensure that
join
is called before any referenced data is dropped - use only types with
'static
lifetime bounds, i.e., those with no or only'static
references (bothBuilder::spawn
andspawn
enforce this property statically)