Only print warning message once when using fallback deserialization
@@ -11,6 +11,7 @@ use futures::{future::Future, ready, stream::Stream};
use pin_project::pin_project;
use std::any::Any;
use std::pin::Pin;
+use std::sync::Once;
use std::task::{Context, Poll};
use std::time::{Duration, Instant};
use thiserror::Error;
@@ -112,11 +113,15 @@ pub mod task {
return JoinHandle::Tokio1x(handle.spawn_blocking(f));
}
+ static WARN: Once = Once::new();
+ WARN.call_once(|| {
use std::io::Write;
let _ = writeln!(
std::io::stderr(),
"Falling back to running blocking code inline. Please use a tokio runtime instead!!"
);
+ });
+
JoinHandle::Fallback(Some(f()))
}
}
@@ -378,5 +383,9 @@ mod test {
assert!(
futures::executor::block_on(task::spawn_blocking_fallback_inline(|| true)).unwrap()
);
+ // Second time still works, even though it doesn't write to stderr.
+ assert!(
+ futures::executor::block_on(task::spawn_blocking_fallback_inline(|| true)).unwrap()
+ );
}
}
