@@ -171,7 +171,7 @@ uniffi::include_scaffolding!("ldk_node");
171171///
172172/// Needs to be initialized and instantiated through [`Builder::build`].
173173pub struct Node {
174- runtime : Arc < RwLock < Option < tokio:: runtime:: Runtime > > > ,
174+ runtime : Arc < RwLock < Option < Arc < tokio:: runtime:: Runtime > > > > ,
175175 stop_sender : tokio:: sync:: watch:: Sender < ( ) > ,
176176 event_handling_stopped_sender : tokio:: sync:: watch:: Sender < ( ) > ,
177177 config : Arc < Config > ,
@@ -211,6 +211,19 @@ impl Node {
211211 /// After this returns, the [`Node`] instance can be controlled via the provided API methods in
212212 /// a thread-safe manner.
213213 pub fn start ( & self ) -> Result < ( ) , Error > {
214+ let runtime =
215+ Arc :: new ( tokio:: runtime:: Builder :: new_multi_thread ( ) . enable_all ( ) . build ( ) . unwrap ( ) ) ;
216+ self . start_with_runtime ( runtime)
217+ }
218+
219+ /// Starts the necessary background tasks, such as handling events coming from user input,
220+ /// LDK/BDK, and the peer-to-peer network.
221+ ///
222+ /// After this returns, the [`Node`] instance can be controlled via the provided API methods in
223+ /// a thread-safe manner.
224+ ///
225+ /// FIXME: Document runtime
226+ pub fn start_with_runtime ( & self , runtime : Arc < tokio:: runtime:: Runtime > ) -> Result < ( ) , Error > {
214227 // Acquire a run lock and hold it until we're setup.
215228 let mut runtime_lock = self . runtime . write ( ) . unwrap ( ) ;
216229 if runtime_lock. is_some ( ) {
@@ -225,8 +238,6 @@ impl Node {
225238 self . config. network
226239 ) ;
227240
228- let runtime = tokio:: runtime:: Builder :: new_multi_thread ( ) . enable_all ( ) . build ( ) . unwrap ( ) ;
229-
230241 // Block to ensure we update our fee rate cache once on startup
231242 let fee_estimator = Arc :: clone ( & self . fee_estimator ) ;
232243 let sync_logger = Arc :: clone ( & self . logger ) ;
@@ -862,9 +873,6 @@ impl Node {
862873 ) ;
863874 }
864875
865- // Shutdown our runtime. By now ~no or only very few tasks should be left.
866- runtime. shutdown_timeout ( Duration :: from_secs ( 10 ) ) ;
867-
868876 log_info ! ( self . logger, "Shutdown complete." ) ;
869877 Ok ( ( ) )
870878 }
0 commit comments