Skip to content

Commit 8512c26

Browse files
committed
Add async { ..await } in remaining places
Since it seems to make a difference to `tokio` (see https://docs.rs/tokio/latest/tokio/time/fn.timeout.html#panics) we make sure the futures are always put in an `async` closure.
1 parent 05dab40 commit 8512c26

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/runtime.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,10 @@ impl Runtime {
6767
{
6868
let mut background_tasks = self.background_tasks.lock().unwrap();
6969
let runtime_handle = self.handle();
70-
background_tasks.spawn_on(future, runtime_handle);
70+
// Since it seems to make a difference to `tokio` (see
71+
// https://docs.rs/tokio/latest/tokio/time/fn.timeout.html#panics) we make sure the futures
72+
// are always put in an `async` / `.await` closure.
73+
background_tasks.spawn_on(async { future.await }, runtime_handle);
7174
}
7275

7376
pub fn spawn_cancellable_background_task<F>(&self, future: F)
@@ -76,7 +79,10 @@ impl Runtime {
7679
{
7780
let mut cancellable_background_tasks = self.cancellable_background_tasks.lock().unwrap();
7881
let runtime_handle = self.handle();
79-
cancellable_background_tasks.spawn_on(future, runtime_handle);
82+
// Since it seems to make a difference to `tokio` (see
83+
// https://docs.rs/tokio/latest/tokio/time/fn.timeout.html#panics) we make sure the futures
84+
// are always put in an `async` / `.await` closure.
85+
cancellable_background_tasks.spawn_on(async { future.await }, runtime_handle);
8086
}
8187

8288
pub fn spawn_background_processor_task<F>(&self, future: F)
@@ -107,7 +113,10 @@ impl Runtime {
107113
// to detect the outer context here, and otherwise use whatever was set during
108114
// initialization.
109115
let handle = tokio::runtime::Handle::try_current().unwrap_or(self.handle().clone());
110-
tokio::task::block_in_place(move || handle.block_on(future))
116+
// Since it seems to make a difference to `tokio` (see
117+
// https://docs.rs/tokio/latest/tokio/time/fn.timeout.html#panics) we make sure the futures
118+
// are always put in an `async` / `.await` closure.
119+
tokio::task::block_in_place(move || handle.block_on(async { future.await }))
111120
}
112121

113122
pub fn abort_cancellable_background_tasks(&self) {
@@ -154,6 +163,9 @@ impl Runtime {
154163
self.background_processor_task.lock().unwrap().take()
155164
{
156165
let abort_handle = background_processor_task.abort_handle();
166+
// Since it seems to make a difference to `tokio` (see
167+
// https://docs.rs/tokio/latest/tokio/time/fn.timeout.html#panics) we make sure the futures
168+
// are always put in an `async` / `.await` closure.
157169
let timeout_res = self.block_on(async {
158170
tokio::time::timeout(
159171
Duration::from_secs(LDK_EVENT_HANDLER_SHUTDOWN_TIMEOUT_SECS),

0 commit comments

Comments
 (0)