Skip to content

Commit 95c7097

Browse files
committed
Move RuntimeSpawner to runtime.rs
In a few commits as we upgrade LDK we'll use `RuntimeSpawner` outside of gossip, making it make much more sense to have it in `runtime.rs` instead.
1 parent 4caf1b6 commit 95c7097

File tree

3 files changed

+20
-20
lines changed

3 files changed

+20
-20
lines changed

src/gossip.rs

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,16 @@
55
// http://opensource.org/licenses/MIT>, at your option. You may not use this file except in
66
// accordance with one or both of these licenses.
77

8-
use std::future::Future;
98
use std::sync::atomic::{AtomicU32, Ordering};
109
use std::sync::Arc;
1110
use std::time::Duration;
1211

13-
use lightning::util::native_async::FutureSpawner;
1412
use lightning_block_sync::gossip::GossipVerifier;
1513

1614
use crate::chain::ChainSource;
1715
use crate::config::RGS_SYNC_TIMEOUT_SECS;
1816
use crate::logger::{log_trace, LdkLogger, Logger};
19-
use crate::runtime::Runtime;
17+
use crate::runtime::{Runtime, RuntimeSpawner};
2018
use crate::types::{GossipSync, Graph, P2PGossipSync, RapidGossipSync};
2119
use crate::Error;
2220

@@ -114,19 +112,3 @@ impl GossipSource {
114112
}
115113
}
116114
}
117-
118-
pub(crate) struct RuntimeSpawner {
119-
runtime: Arc<Runtime>,
120-
}
121-
122-
impl RuntimeSpawner {
123-
pub(crate) fn new(runtime: Arc<Runtime>) -> Self {
124-
Self { runtime }
125-
}
126-
}
127-
128-
impl FutureSpawner for RuntimeSpawner {
129-
fn spawn<T: Future<Output = ()> + Send + 'static>(&self, future: T) {
130-
self.runtime.spawn_cancellable_background_task(future);
131-
}
132-
}

src/runtime.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ use std::future::Future;
99
use std::sync::{Arc, Mutex};
1010
use std::time::Duration;
1111

12+
use lightning::util::native_async::FutureSpawner;
13+
1214
use tokio::task::{JoinHandle, JoinSet};
1315

1416
use crate::config::{
@@ -219,3 +221,19 @@ enum RuntimeMode {
219221
Owned(tokio::runtime::Runtime),
220222
Handle(tokio::runtime::Handle),
221223
}
224+
225+
pub(crate) struct RuntimeSpawner {
226+
runtime: Arc<Runtime>,
227+
}
228+
229+
impl RuntimeSpawner {
230+
pub(crate) fn new(runtime: Arc<Runtime>) -> Self {
231+
Self { runtime }
232+
}
233+
}
234+
235+
impl FutureSpawner for RuntimeSpawner {
236+
fn spawn<T: Future<Output = ()> + Send + 'static>(&self, future: T) {
237+
self.runtime.spawn_cancellable_background_task(future);
238+
}
239+
}

src/types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ use crate::chain::ChainSource;
3535
use crate::config::ChannelConfig;
3636
use crate::data_store::DataStore;
3737
use crate::fee_estimator::OnchainFeeEstimator;
38-
use crate::gossip::RuntimeSpawner;
3938
use crate::logger::Logger;
4039
use crate::message_handler::NodeCustomMessageHandler;
4140
use crate::payment::PaymentDetails;
41+
use crate::runtime::RuntimeSpawner;
4242

4343
/// A supertrait that requires that a type implements both [`KVStore`] and [`KVStoreSync`] at the
4444
/// same time.

0 commit comments

Comments
 (0)