@@ -223,9 +223,8 @@ impl BackgroundProcessor {
223
223
channel_manager. process_pending_events ( & event_handler) ;
224
224
chain_monitor. process_pending_events ( & event_handler) ;
225
225
226
- // We wait up to 100ms, but on a mobile device without a ton of activity, if we get
227
- // put in the background and paused, this is likely where it will happen, causing
228
- // the wait time to be substantially longer.
226
+ // We wait up to 100ms, but track how long it takes to detect being put to sleep,
227
+ // see `await_start`'s use below.
229
228
let await_start = Instant :: now ( ) ;
230
229
let updates_available =
231
230
channel_manager. await_persistable_update_timeout ( Duration :: from_millis ( 100 ) ) ;
@@ -246,14 +245,14 @@ impl BackgroundProcessor {
246
245
channel_manager. timer_tick_occurred ( ) ;
247
246
last_freshness_call = Instant :: now ( ) ;
248
247
}
249
- if await_time > Duration :: from_secs ( 1 ) {
248
+ if await_time. as_secs ( ) > 2 * PING_TIMER {
250
249
// On various platforms, we may be starved of CPU cycles for several reasons.
251
250
// E.g. on iOS, if we've been in the background, we will be entirely paused.
252
251
// Similarly, if we're on a desktop platform and the device has been asleep, we
253
252
// may not get any cycles.
254
253
// In any case, if we've been entirely paused for more than double our ping
255
254
// timer, we should have disconnected all sockets by now (and they're probably
256
- // dead anyway), so disconnect them by calling `timer_tick_occurred()` twice .
255
+ // dead anyway).
257
256
// Note that we have to take care to not get here just because user event
258
257
// processing was slow at the top of the loop. For example, the sample client
259
258
// may call Bitcoin Core RPCs during event handling, which very often takes
0 commit comments