Pier Pier - 1 year ago 66
Javascript Question

How to cancel a once() call before answer?

So what's the proper way of canceling a

call before the database has answered?

I have a use case where if the database takes more than a few seconds to answer, I don't want the answer. I'm using a promise notation, but if required, I could switch to the callback notation.

Promise notation:


Callback notation:

firebase.database().ref('something').once('value',snapshot => {...})

Answer Source

You can unregister listeners by calling off().

See the reference documentation for off(). It only speaks of working for on(), but it will work for once() listeners too.

I'm not sure what it would accomplish though, as the value listener will fire right away anyway.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download