Skip to content

Commit

Permalink
Forget TaskHandles instead of dropping
Browse files Browse the repository at this point in the history
dropping the handle aborts the task
  • Loading branch information
mankinskin committed Feb 6, 2021
1 parent 68a6d32 commit efb6df9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
14 changes: 11 additions & 3 deletions src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ impl<T: Future<Output = ()> + Send> Task for T {}
pub trait TaskExecutor {
fn spawn(&self, future: Pin<Box<dyn Task>>) -> Result<Box<dyn TaskExec<()>>, Box<dyn Error>>;
}
pub trait TaskExec<T: Send>: Future<Output = Result<T, Box<dyn Error>>> + Unpin + Send + Sync {
pub trait TaskExec<T: Send>:
Future<Output = Result<T, Box<dyn Error>>> + Unpin + Send + Sync
{
fn abort(self: Box<Self>);
fn forget(self: Box<Self>);
}
Expand Down Expand Up @@ -65,7 +67,10 @@ mod executor_impl {
use super::*;
pub struct TokioExecutor(pub tokio::runtime::Handle);
impl TaskExecutor for TokioExecutor {
fn spawn(&self, future: Pin<Box<dyn Task>>) -> Result<Box<dyn TaskExec<()>>, Box<dyn Error>> {
fn spawn(
&self,
future: Pin<Box<dyn Task>>,
) -> Result<Box<dyn TaskExec<()>>, Box<dyn Error>> {
Ok(Box::new(TokioJoinHandle(self.0.spawn(future))))
}
}
Expand Down Expand Up @@ -104,7 +109,10 @@ mod executor_impl {
}
pub struct FuturesExecutor(pub futures::executor::ThreadPool);
impl TaskExecutor for FuturesExecutor {
fn spawn(&self, future: Pin<Box<dyn Task>>) -> Result<Box<dyn TaskExec<()>>, Box<dyn Error>> {
fn spawn(
&self,
future: Pin<Box<dyn Task>>,
) -> Result<Box<dyn TaskExec<()>>, Box<dyn Error>> {
self.0
.spawn_with_handle(future)
.map(|h| Box::new(FuturesJoinHandle(h)) as Box<dyn TaskExec<()>>)
Expand Down
4 changes: 3 additions & 1 deletion src/kernel/kernel_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ impl KernelRef {
let mut tx = self.tx.clone();
sys.run(async move {
drop(tx.send(msg).await);
}).unwrap().forget();
})
.unwrap()
.forget();
}
}

Expand Down

0 comments on commit efb6df9

Please sign in to comment.