Are any additional dependencies required to use Worker class outside of stdlib?
j
Are any additional dependencies required to use Worker class outside of stdlib?
d
Outside?
All you need is stdlib if that's what you're asking.
j
Yes, Using Kotlin 1.3.31: Unresolved reference: Worker
import kotlin.native.concurrent.Worker fun test() { Worker.start() }
The rest of the stdlib is accessible as expected
d
Can I see your gradle file?
j
d
Is your Worker code in
src/iosMain/kotlin
?
j
No, common
Its failing compile on step: > Task libcompileDebugKotlinAndroid FAILED
d
It won't work in common.
Only in native.
šŸ™ 1
j
Ok ic. So workers aren't supported on JVM?
d
Nope, it's not supported.
šŸ‘ 1
j
When developing iOS/Android codebases current recommendations would be to use coroutine for Android/JVM and Worker for native then?
If use coroutine on native its limited to a single thread currently is my understanding
ktor client (native) will perform non-blocking io through right?
k
I use an executor on jvm and worker on native for ā€œsimpleā€ cases
Looking at that it definitely needs some clean up, but it works.
You can use a coroutine, but not with all features. We have a simple version that lets you suspend main thread and do some background work
I haven’t put much effort into a ā€œlibraryā€ as I’m expecting whenever multithreaded coroutines hits, that will kind of replace whatever is published
Two things to check out
It does work, but I think it needs extensions and again, when MT coroutines hit, I expect that library will have competition. Again, though, it does work.
@basher is also releasing a library at some point to help with MT coroutines while we’re waiting for ā€œofficialā€ coroutines
j
šŸ’Æ
Thanks!
k
Finally, I’m rewriting Stately (actually right now), and maybe adding a simple executor in common would be useful
šŸ‘Œ 1
I’m chock full of info
j
For now I just want a basic callback that can be used in by code in common module
k
Well, spoilers. The trick is keeping your callback function in the main thread so it doesn’t need to be frozen
j
Thanks I'm re-reading your stranger threads articles. Worker will manage its own thread pool?
To cancel an operation there is worker.requestTermination but that will end all jobs in queue. How to terminate a single queued job?
b
Worker is backed by a single thread
k
Yes. 1 thread. JB engineers caveat that that may change in the future, but it's been 1 thread since I looked at it
j
šŸ¤” So a single IO operation will block the queue and multiple Workers would be required?
b
Yep!
j
Ok np. Is this a temporary limitation?
b
I would assume not
a
I would say it's by design
If you need a pool of threads (like ExecutorService in Java) you can check how it's done in Reaktive (https://github.com/badoo/Reaktive/tree/master/reaktive/src/nativeCommonMain/kotlin/com/badoo/reaktive/looperthread) or just use it šŸ˜€ There are two strategies at the moment: fixed and unbound thread pools
j
Looking forward to trying out Reaktive when iOS port is ready šŸ™‚
Thanks for responses everyone
a
iOS (as well as Linux) code is there, artifacts will be published soon
āž• 1
k
I’ve been using Reaktive for iOS. I publish it to our namespace until there’s an official version that works with metadata
b
Code is up. Release to mavencentral/jcenter coming next week: https://kotlinlang.slack.com/archives/C0BJ0GTE2/p1561161573109900
šŸŒ¶ļø 1