add unconstrained feature to service worker

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2025-02-06 23:58:45 +00:00 committed by strawberry
parent 5428526120
commit 59c073d0d8
3 changed files with 23 additions and 4 deletions

View file

@ -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))
}