mirror of
https://github.com/Zenithsiz/dcb.git
synced 2026-02-04 00:21:57 +00:00
Fixed task::spawn not properly running things in another thread.
This commit is contained in:
parent
a41b04acb3
commit
72c74b89d6
@ -6,7 +6,6 @@ edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
# Dcb
|
||||
dcb = { path = "../../dcb" }
|
||||
dcb-bytes = { path = "../../dcb-bytes" }
|
||||
dcb-util = { path = "../../dcb-util" }
|
||||
dcb-cdrom-xa = { path = "../../dcb-cdrom-xa" }
|
||||
|
||||
@ -25,4 +25,7 @@ ref-cast = "1.0.6"
|
||||
|
||||
# Thread
|
||||
rayon = "1.5.1"
|
||||
futures = "0.3.15"
|
||||
futures = "0.3.15"
|
||||
|
||||
# Logging
|
||||
log = "0.4.14"
|
||||
@ -9,7 +9,7 @@ use std::{
|
||||
};
|
||||
|
||||
/// Spawns a task and returns a future for awaiting it's value
|
||||
pub fn spawn<T: Send>(f: impl FnOnce() -> T + Send) -> ValueFuture<T> {
|
||||
pub fn spawn<T: Send + 'static>(f: impl FnOnce() -> T + Send + 'static) -> ValueFuture<T> {
|
||||
// Create the value mutex
|
||||
let mutex = Arc::new(Mutex::new(None));
|
||||
let future = ValueFuture {
|
||||
@ -18,8 +18,9 @@ pub fn spawn<T: Send>(f: impl FnOnce() -> T + Send) -> ValueFuture<T> {
|
||||
};
|
||||
|
||||
// Spawn the task
|
||||
rayon::scope(move |_| {
|
||||
*mutex.lock().expect("Poisoned") = Some(f());
|
||||
rayon::spawn(move || {
|
||||
let value = f();
|
||||
*mutex.lock().expect("Poisoned") = Some(value);
|
||||
});
|
||||
|
||||
// And return the future
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user