app_sciences
app_sciences

Reputation: 813

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?

Upvotes: 3

Views: 1388

Answers (1)

Doug Stevenson
Doug Stevenson

Reputation: 317372

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.

Upvotes: 4

Related Questions