prof18 / RSS-Parser

A Kotlin Multiplatform library to parse a RSS Feed
Apache License 2.0
509 stars 129 forks source link

Allow parse on current thread #100

Closed gregko closed 1 year ago

gregko commented 2 years ago

I'm creating a parser and want to parse a raw string on a current, background thread on Android. Why am I forced to use some scope.launch{}, which in this situation is simply a waste - create another thread, launch it, etc., while I want to do all the parsing on the current thread. My app is aware of background processing at this time and is already showing to the user some progress indicator only.

Is this possible with the current release of RSS-Parser library? If so, how?

prof18 commented 1 year ago

On the Kotlin side, the library follows the same principles as many networking and database libraries: it handles automatically internally the switch from the main thread. For that, it uses Kotlin coroutines and Coroutines doesn't start a new thread from scratch. So you don't have to worry about unnecessary computation if you start the parsing with coroutines.

The Java side is using an ExecutorService, so it starts a thread. However, the Java side is not maintained anymore.