Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase once() timeout

I am using Firebase once() method to retrieve a value in a React Native mobile app. Trouble is if the phone is offline, once() never returns. Documentation says that ref.off() method should cancel callbacks, but that doesn't seem to work.

I'm guessing that off() doesn't apply to once() callbacks. If so how would I create a timeout?

like image 417
app_sciences Avatar asked Mar 13 '26 18:03

app_sciences


1 Answers

There's no such concept as a timeout when dealing with Firebase Realtime Database APIs on any platform. Clients are generally not expected to know or care if they're online or offline, except by querying a special location that indicates as such.

If you want to implement your own timeout for a query (for the web), use setTimeout to force some code to execute after some amount of time. You'll have to be careful to coordinate between your database callback and the setTimeout callback such that if one triggers, the other one does not.

like image 199
Doug Stevenson Avatar answered Mar 16 '26 08:03

Doug Stevenson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!