-
Notifications
You must be signed in to change notification settings - Fork 168
Add Asynchronouts/Deferred implementation to Firestore/Database/etc #497
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
What gives you the impression launch takes time to spin up?
What scope would you await the Deferred returned from the proposed api? Doesn't that give you the same problem?
Just launch it in the GlobalScope instead then? That's essentially what's happening if the API was to return Deferred. Also since (at least for android) we are using |
Launching on Globalscope is a big no-no in my book, and its entirely unnecessary to launch anything if you want a deferred. In the end, users wrapping the suspend methods in |
I believe the unnecessary overhead is negligible and not worth the api bloat proposed here. Requiring lifecycle management is good thing - it forces developers to consider the lifetime of the async operation and is the reason for the whole coroutines scope concept. |
Just want to understand your usecase, it sounds like your job shouldn't be bound to the VM scope because you don't want it cancelling when the viewmodel scope is closed.
I don't think its a no no, especially when you don't want it to be bound to a particular scope. Assuming it is android, If you want to be super safe, you could create an application scope that is associated to your Application and use this instead? |
I tend to agree with @nbransby here. My experience is that writing to Firestore already is really fast, because afaik it defaults to writing to the local cache first and the synchronizes async. Write functions returns almost immediately, even when writing fails due to Rules or what not. @Daeda88 how much data are we talking about here? 10 doc/s? 100 docs/s? More? |
Wanted to start a discussion on this, so writing a ticket instead of a full on PR for a change. A suggestion for an implementation of this was originally in #448 but was removed because I couldn't properly clarify it at the time (someone else within our company had written it) and I felt it was best to take it out of the PR for clarity.
Consider the following usecase:
Then
To solve this, it could be considered to add a non-suspended (deferred) approach to the library. Where the methods are not suspended at all, but just return a
Deferred
of the result. Since the platform APIs do nothing with coroutines, this is very straightforward.It may be argued that you can just call the suspended methods within
scope.async {}
but that means you need to have a coroutineScope, which adds a lot of overhead for high volumes of data and has some form of a lifecycle. Or, to look at it from another way: even though the firebase implementation is suspended, since the internal implementation is not, actions like cancelling the scope have little effect on the interaction with the internal firebase sdk. So from both perspectives, coroutineScopes are not strictly required nor necessarily even beneficial.My suggestion boils down to this.
Current code:
New code:
If others see the benefits of adding an async implementation as well, Im happy to make a PR for it.
The text was updated successfully, but these errors were encountered: