firebase / firebase-unity-sdk

The Firebase SDK for Unity
http://firebase.google.com
Apache License 2.0
201 stars 34 forks source link

Auth and DB Task Cancellation #330

Open jmarisalandanan opened 5 years ago

jmarisalandanan commented 5 years ago

Please fill in the following fields:

Unity editor version: Firebase Unity SDK version: 2018.3 Firebase plugins in use (Auth, Database, etc.): Auth, Database Platform you are using the Unity editor on (Mac, Windows, or Linux): Mac Platform you are targeting (iOS, Android, and/or desktop): Android

Just a question, is there any known way/example on cancelling auth and DB tasks? I want to do something like a timeout and cancel started tasks in case of poor/no network. Additionally I need to cancel tasks if user leaves the screen while auth and DB tasks are not finished.

a-maurice commented 5 years ago

Unfortunately, currently there is no way to cancel the tasks from Auth and Database. The best you could do now is handle it in the task completion, undoing whatever action is needed if you want to.

jmarisalandanan commented 5 years ago

Thanks for the answer! That could work, how ever in the case of Timeout because of poor/no network task wouldn't get completed right? Any ideas on how to handle this properly? I'm currently thinking of possible workarounds for this, just asking in case you have any insights on how to approach this matter.

chkuang-g commented 4 years ago

@jmarisalandanan AFAIK, Database on Android would attempt to reconnect back to the server in poor/no network condition. And it will fail the Task if it retried too many times. I think Auth should have similar mechanics.

There is no proper way to actually implement timeout and cancel operation from C# level. Even you throw away the Task you got, in Android SDK level, it will still attempt to send the request until it gave up.

Shawn

pistoleta commented 4 years ago

hehe this was exactly was I was looking for, it's a shame it's not possible. pistoleta.

kimcatsq commented 4 years ago

Will we have the ability to cancel the task? or set a shorter timeout?

I know I can check if Application has connectivity before calling the Firebase functions. On mobile losing connection is quite common in spotty areas. Currently in my editor, the firebase cloud function call is taking 2min 30sec to time out. It's way too long for players to wait. I could time out the UI, force player to go back 1 screen and let the task run in the background. But if player trigger the call again before the timeout, it would eventually crash Unity. :-(