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,
)
| 411 | /// I (pgoldman 2024-02-22) believe that our Rayon threads only ever send to unbounded channels, |
| 412 | /// and therefore never wait. |
| 413 | fn 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)] |
| 434 | pub struct DatabaseCores(Vec<CoreId>); |