Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/stdx/src/thread.rs')
-rw-r--r--crates/stdx/src/thread.rs15
1 files changed, 6 insertions, 9 deletions
diff --git a/crates/stdx/src/thread.rs b/crates/stdx/src/thread.rs
index 6c742fecf1..a34e9e4a65 100644
--- a/crates/stdx/src/thread.rs
+++ b/crates/stdx/src/thread.rs
@@ -26,12 +26,12 @@ pub use pool::Pool;
/// # Panics
///
/// Panics if failed to spawn the thread.
-pub fn spawn<F, T>(intent: ThreadIntent, f: F) -> JoinHandle<T>
+pub fn spawn<F, T>(intent: ThreadIntent, name: String, f: F) -> JoinHandle<T>
where
F: (FnOnce() -> T) + Send + 'static,
T: Send + 'static,
{
- Builder::new(intent).spawn(f).expect("failed to spawn thread")
+ Builder::new(intent, name).spawn(f).expect("failed to spawn thread")
}
pub struct Builder {
@@ -42,13 +42,8 @@ pub struct Builder {
impl Builder {
#[must_use]
- pub fn new(intent: ThreadIntent) -> Self {
- Self { intent, inner: jod_thread::Builder::new(), allow_leak: false }
- }
-
- #[must_use]
- pub fn name(self, name: String) -> Self {
- Self { inner: self.inner.name(name), ..self }
+ pub fn new(intent: ThreadIntent, name: impl Into<String>) -> Self {
+ Self { intent, inner: jod_thread::Builder::new().name(name.into()), allow_leak: false }
}
#[must_use]
@@ -56,6 +51,8 @@ impl Builder {
Self { inner: self.inner.stack_size(size), ..self }
}
+ /// Whether dropping should detach the thread
+ /// instead of joining it.
#[must_use]
pub fn allow_leak(self, allow_leak: bool) -> Self {
Self { allow_leak, ..self }