Skip to content
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

WCSessionStore APIs are not async friendly. #66

Open
prashanOS opened this issue Apr 26, 2022 · 2 comments
Open

WCSessionStore APIs are not async friendly. #66

prashanOS opened this issue Apr 26, 2022 · 2 comments

Comments

@prashanOS
Copy link

Hi from OpenSea! We have found an issue when enabling Android's StrictMode. It fails because FileWCSessionStore is doing file I/O on the main thread.

The WCSessionStore's methods are all synchronous, but a store (unless it is purely in-memory) is by nature asynchronous. In general, this means implementations would have to block the current thread while doing either file or network I/O. store() and remove() methods could maybe be implemented as fire-and-forget methods, but then we lose access to Kotlin's built-in structured concurrency.

With the provided FileWCSessionStore implementation, this means we are blocking the main thread while doing file I/O whenever these methods are called. FileWCSessionStore is also doing file I/O on the main thread in its' init block.

The proposed solution would be to make these methods suspend functions. Then, consumers can use their own coroutine scope to run these methods. This does mean that WCSession would need to take in a coroutine scope to launch these new suspend functions from.

@jemshit
Copy link

jemshit commented Sep 21, 2022

@prashanOS try this, let me know if you have issues

@jemshit
Copy link

jemshit commented Oct 3, 2022

Hey guys,
i see you're trying to improve this library, i have written it from scratch using coroutines, you could try it instead. We're already using it in prod.

@prashanOS @mhernand40 @matthewrkula

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants