bmsantos
08/28/2017, 1:21 PMfabianterhorst
08/29/2017, 10:03 PMjondotan
08/30/2017, 5:36 PMjondotan
08/31/2017, 11:15 AMtunedal
08/31/2017, 3:19 PMagrosner
08/31/2017, 5:24 PMharmony
09/01/2017, 1:49 AMredrield
09/01/2017, 2:23 AMredrield
09/01/2017, 2:24 AMandreasmattsson
09/01/2017, 8:26 AMlibrary.invoke(arg) { value -> doSomething(value) }
Now what I'd like to do is wrap this somehow so that instead of using a callback my wrapping method returns a Sequence (going from a push to a pull style API).
My first attempt was to use buildSequence:
buildSequence { library.invoke(arg) { value -> yield(value) } }
But this gives Suspension functions can be called only within coroutine body
.
The Wrapping callbacks section in the documentation here looked promising:
https://github.com/Kotlin/kotlin-coroutines/blob/master/kotlin-coroutines-informal.md#wrapping-callbacks
But as far as I can tell this suspendCoroutine
trick only works if the callback is called only once by the library. Mine is called many many times, and I want to have a sequence where I can consume items one by one and not have to gather them in a list first.
Channels looks like a good approach but AFAIK they are only available in the kotlinx.coroutines
package that does not work in Kotlin Native.
Any suggestions? Are there any "out of the box" or idiomatic solutions for this that don't involve manually implementing a producer/consumer pattern using C/threading concurrency stuff?andreasmattsson
09/04/2017, 12:46 PMC:\Users\w64vm\kotlin-native\runtime\src\main\cpp\Memory.cpp:751: runtime assert: Memory leaks found
No args, no errors:
data class WorkerArgs(val unused: Unit = Unit)
val worker = startWorker()
val future = worker.schedule(
TransferMode.CHECKED,
{ },
{ }
)
future.consume { _ -> }
worker.requestTermination().consume { _ -> }
With args, prints error:
data class WorkerArgs(val unused: Unit = Unit)
val worker = startWorker()
val future = worker.schedule(
TransferMode.CHECKED,
{ WorkerArgs() }, // <-- this line
{ }
)
future.consume { _ -> }
worker.requestTermination().consume { _ -> }
Do I need to manually dispose the WorkerArgs instance somehow?nimtiazm
09/09/2017, 1:00 PMnimtiazm
09/09/2017, 1:01 PMclaudiug
09/17/2017, 10:01 AMredrield
09/17/2017, 9:59 PMandreasmattsson
09/18/2017, 9:16 AMkonan.worker.*
APIs to do some background processing (in a loop), and it's working well, but now I'd like to add an ability to gracefully cancel/abort (early-exit) from the background loop.
What's the correct way to implement this? Is there some flag I can check for in my background loop that is set when requestTermination
has been called?
I understand there are restrictions on sharing state, so for example I get an IllegalStateException
if I try to pass in a BooleanVar
into my worker args.jkbbwr
09/18/2017, 9:22 AMbenleggiero
09/19/2017, 10:18 AMjkbbwr
09/20/2017, 4:35 PMandreasmattsson
09/21/2017, 8:23 AMalloc
a long on the heap)tunedal
09/24/2017, 5:00 PM"hello".cstr.size == "hello".length + 2
? Shouldn't it just have one more byte for the NUL?ariff
09/25/2017, 11:46 PMalexcouch
09/26/2017, 11:00 PMharmony
09/29/2017, 1:04 AMFrancis
09/29/2017, 12:32 PMbuild.sh
but it work with gradlew
. So my question is: Is gradle required to build native (doc say build.sh
should do) or I'm doing something wrong?fab
10/03/2017, 10:00 AMaaverin
10/03/2017, 11:13 AMagrosner
10/03/2017, 2:08 PMnapperley
10/08/2017, 2:30 AMharmony
10/08/2017, 2:52 AMharmony
10/08/2017, 2:52 AMnapperley
10/08/2017, 6:33 AMtunedal
10/08/2017, 10:43 AMmsink
10/08/2017, 11:12 AMtunedal
10/08/2017, 11:42 AMsksk
10/08/2017, 12:05 PMmsink
10/08/2017, 12:35 PMelect
10/08/2017, 8:55 PMnapperley
10/08/2017, 10:57 PMelect
10/09/2017, 7:50 AMsksk
10/09/2017, 9:15 PMrwachol
10/10/2017, 3:32 PM