@@ -350,14 +350,54 @@ macro_rules! define_run_body {
350
350
///
351
351
/// `sleeper` should return a future which completes in the given amount of time and returns a
352
352
/// boolean indicating whether the background processing should exit. Once `sleeper` returns a
353
- /// future which outputs true, the loop will exit and this function's future will complete.
353
+ /// future which outputs ` true` , the loop will exit and this function's future will complete.
354
354
///
355
355
/// See [`BackgroundProcessor::start`] for information on which actions this handles.
356
356
///
357
357
/// Requires the `futures` feature. Note that while this method is available without the `std`
358
358
/// feature, doing so will skip calling [`NetworkGraph::remove_stale_channels_and_tracking`],
359
359
/// you should call [`NetworkGraph::remove_stale_channels_and_tracking_with_time`] regularly
360
360
/// manually instead.
361
+ ///
362
+ /// For example, in order to process background events in a [Tokio](https://tokio.rs/) task, you
363
+ /// could setup `process_events_async` like this:
364
+ /// ```ignore
365
+ /// let background_persister = Arc::clone(&my_persister);
366
+ /// let background_event_handler = Arc::clone(&my_event_handler);
367
+ /// let background_chain_mon = Arc::clone(&my_chain_monitor);
368
+ /// let background_chan_man = Arc::clone(&mu_channel_manager);
369
+ /// let background_gossip_sync = GossipSync::p2p(Arc::clone(&my_gossip_sync));
370
+ /// let background_peer_man = Arc::clone(&my_peer_manager);
371
+ /// let background_logger = Arc::clone(&my_logger);
372
+ /// let background_scorer = Arc::clone(&my_scorer);
373
+ ///
374
+ /// // Setup the sleeper.
375
+ /// let should_stop = AtomicBool::new(false);
376
+ ///
377
+ /// let sleeper = |d| async move {
378
+ /// tokio::time::sleep(d).await;
379
+ /// should_stop.load(Ordering::Relaxed)
380
+ /// };
381
+ ///
382
+ /// tokio::spawn(async move {
383
+ /// process_events_async(
384
+ /// background_persister,
385
+ /// |e| background_event_handler.handle_event(e),
386
+ /// background_chain_mon,
387
+ /// background_chan_man,
388
+ /// background_gossip_sync,
389
+ /// background_peer_man,
390
+ /// background_logger,
391
+ /// Some(background_scorer),
392
+ /// sleeper,
393
+ /// )
394
+ /// .await
395
+ /// .expect("Failed to process events");
396
+ /// });
397
+ ///
398
+ /// // Stop the background processing.
399
+ /// should_stop.store(true, Ordering::Relaxed);
400
+ ///```
361
401
#[ cfg( feature = "futures" ) ]
362
402
pub async fn process_events_async <
363
403
' a ,
0 commit comments