Fix tokio panic for async handlers

This commit is contained in:
Félix Saparelli 2021-08-23 02:35:28 +12:00
parent 931648a955
commit 74d8e73817
No known key found for this signature in database
GPG Key ID: B948C4BAE44FC474
1 changed files with 6 additions and 4 deletions

View File

@ -86,7 +86,7 @@
use std::{error::Error, future::Future, io::Write, marker::PhantomData};
use tokio::runtime::Handle;
use tokio::{runtime::Handle, task::block_in_place};
use crate::error::RuntimeError;
@ -163,9 +163,11 @@ where
{
fn handle(&mut self, data: T) -> Result<(), Box<dyn Error>> {
// this will always be called within watchexec context, which runs within tokio
Handle::current()
.block_on((self)(data))
.map_err(|e| Box::new(e) as _)
block_in_place(|| {
Handle::current()
.block_on((self)(data))
.map_err(|e| Box::new(e) as _)
})
}
}