MCPcopy Create free account
hub / github.com/clockworklabs/SpacetimeDB / thread_spawn_handler

Function thread_spawn_handler

crates/core/src/startup.rs:413–431  ·  view source on GitHub ↗

A Rayon [spawn_handler](https://docs.rs/rustc-rayon-core/latest/rayon_core/struct.ThreadPoolBuilder.html#method.spawn_handler) which enters the given Tokio runtime at thread startup, so that the Rayon workers can send along async channels. Other than entering the `rt`, this spawn handler behaves identitically to the default Rayon spawn handler, as documented in https://docs.rs/rustc-rayon-core/0.

(
    rt: &tokio::runtime::Handle,
)

Source from the content-addressed store, hash-verified

411/// I (pgoldman 2024-02-22) believe that our Rayon threads only ever send to unbounded channels,
412/// and therefore never wait.
413fn thread_spawn_handler(
414 rt: &tokio::runtime::Handle,
415) -> impl FnMut(rayon::ThreadBuilder) -> Result<(), std::io::Error> + '_ {
416 move |thread| {
417 let rt = rt.clone();
418 let mut builder = std::thread::Builder::new();
419 if let Some(name) = thread.name() {
420 builder = builder.name(name.to_owned());
421 }
422 if let Some(stack_size) = thread.stack_size() {
423 builder = builder.stack_size(stack_size);
424 }
425 builder.spawn(move || {
426 let _rt_guard = rt.enter();
427 thread.run()
428 })?;
429 Ok(())
430 }
431}
432
433#[derive(Default)]
434pub struct DatabaseCores(Vec<CoreId>);

Callers 1

configureMethod · 0.85

Calls 7

nameMethod · 0.65
newFunction · 0.50
OkFunction · 0.50
cloneMethod · 0.45
to_ownedMethod · 0.45
spawnMethod · 0.45
runMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…