add unconstrained feature to service worker
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
use std::{panic::AssertUnwindSafe, sync::Arc, time::Duration};
|
||||
|
||||
use conduwuit::{debug, debug_warn, error, trace, utils::time, warn, Err, Error, Result, Server};
|
||||
use futures::FutureExt;
|
||||
use futures::{FutureExt, TryFutureExt};
|
||||
use tokio::{
|
||||
sync::{Mutex, MutexGuard},
|
||||
task::{JoinHandle, JoinSet},
|
||||
@@ -183,9 +183,14 @@ async fn worker(service: Arc<dyn Service>) -> WorkerResult {
|
||||
let service_ = Arc::clone(&service);
|
||||
let result = AssertUnwindSafe(service_.worker())
|
||||
.catch_unwind()
|
||||
.await
|
||||
.map_err(Error::from_panic);
|
||||
|
||||
let result = if service.unconstrained() {
|
||||
tokio::task::unconstrained(result).await
|
||||
} else {
|
||||
result.await
|
||||
};
|
||||
|
||||
// flattens JoinError for panic into worker's Error
|
||||
(service, result.unwrap_or_else(Err))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user