Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove Firestore Snapshot Listener From Inside Listener

Super simple question. I need to remove a firestore snapshot listener once I hit a certain point inside of my listener. Seems like this should be super easy but I can't figure it out. Thanks!

Example code:

val registration = gameRef.addSnapshotListener { snapshot, e ->
     //code....

     //if(condition is meet){
     //    destroy this listener
     //}
}
like image 507
Jared Avatar asked Jan 01 '23 21:01

Jared


1 Answers

Assume that the listener is returned immediately and that its callback won't be invoked until after it's returned by the function:

var feedback: ListenerRegistration? = null
feedback = gameRef.addSnapshotListener { snapshot, e ->
    feedback?.remove()
}
like image 183
Doug Stevenson Avatar answered Jan 12 '23 15:01

Doug Stevenson