add_sync_notifier in EthPubSubClient holds on to a Client for too long (#10689)

Need a weak ref so shutdown works
This commit is contained in:
David 2019-05-23 07:50:45 +02:00 committed by GitHub
parent 26d1303034
commit d250f348a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -64,14 +64,16 @@ impl<C> EthPubSubClient<C>
where where
F: 'static + Fn(SyncState) -> Option<pubsub::PubSubSyncStatus> + Send F: 'static + Fn(SyncState) -> Option<pubsub::PubSubSyncStatus> + Send
{ {
let handler = self.handler.clone(); let weak_handler = Arc::downgrade(&self.handler);
self.handler.executor.spawn( self.handler.executor.spawn(
receiver.for_each(move |state| { receiver.for_each(move |state| {
if let Some(status) = f(state) { if let Some(status) = f(state) {
if let Some(handler) = weak_handler.upgrade() {
handler.notify_syncing(status); handler.notify_syncing(status);
return Ok(()) return Ok(())
} }
}
Err(()) Err(())
}) })
) )