File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed
Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -141,6 +141,37 @@ impl LightClient<Idle> {
141141 } ;
142142 ( client, requester, logging)
143143 }
144+
145+ /// Start the client on a detached operating system thread. This method is used when there is
146+ /// no [`tokio::runtime::Runtime`] available.
147+ ///
148+ /// # Returns
149+ ///
150+ /// - A [`LightClient`] in [`Active`] state.
151+ /// - A [`Requester`] to publish transactions or fetch data.
152+ /// - [`LoggingSubscribers`] to process messages from the sync process.
153+ pub fn start_detached_thread ( mut self ) -> ( LightClient < Active > , Requester , LoggingSubscribers ) {
154+ let logging = core:: mem:: take ( & mut self . logging ) . expect ( "node starts once" ) ;
155+ let requester = core:: mem:: take ( & mut self . requester ) . expect ( "node starts once" ) ;
156+ let node = core:: mem:: take ( & mut self . node ) . expect ( "node starts once" ) ;
157+ std:: thread:: spawn ( || {
158+ tokio:: runtime:: Builder :: new_multi_thread ( )
159+ . enable_all ( )
160+ . build ( )
161+ . unwrap ( )
162+ . block_on ( async move {
163+ let _ = node. run ( ) . await ;
164+ } )
165+ } ) ;
166+ let client = LightClient {
167+ requester : None ,
168+ logging : None ,
169+ update_subscriber : self . update_subscriber ,
170+ node : None ,
171+ _marker : core:: marker:: PhantomData ,
172+ } ;
173+ ( client, requester, logging)
174+ }
144175}
145176
146177impl LightClient < Active > {
You can’t perform that action at this time.
0 commit comments