bitkid
04/05/2018, 11:38 AMmarstran
04/05/2018, 11:38 AMmarstran
04/05/2018, 11:39 AMClient
that suspends for 1 second, instead of mocking it.bitkid
04/05/2018, 11:39 AMbitkid
04/05/2018, 11:45 AMbitkid
04/05/2018, 12:02 PMbitkid
04/05/2018, 12:05 PMmarstran
04/05/2018, 12:08 PMsuspendCoroutine
function. Check this: https://github.com/Kotlin/kotlin-coroutines/blob/master/kotlin-coroutines-informal.md#wrapping-callbacksbitkid
04/05/2018, 12:10 PMJoey Heck
04/05/2018, 6:42 PMgroostav
04/05/2018, 6:42 PMSequentialExecutorFacade
, which takes an executor as "backing executor", and simply ensures that all calls to submit
, execute
, schedule (if scheduled)
, etc, all run jobs seemingly on a single thread. I dont need gaurentees about which thread its run on but I want gaurentees that only 1 job will be run at a time.groostav
04/05/2018, 6:43 PMgroostav
04/05/2018, 6:44 PMExecutorService
that gives me the same behaviour as the code put in an actor {
block --albeit that code gets this behaviour through `Channel`s semantics rather than intrinsicallyvenkat
04/06/2018, 1:17 AMproducers
(think: sources),
- actors
(=sinks) and
- Channels
(=edges),
Throw in:
- transforms
and
- pipes
for easy hookup
we end up with DAGs
, not unlike NodeJS’ streams.
Here’s an early proof of concept: https://github.com/venkatperi/kotlin-coroutines-lib/blob/master/src/main/kotlin/com/vperi/kotlinx/coroutines/experimental/TransformChannel.kt
runBlocking {
FS.createReader(inputFile.toPath())
.pipe(decodeUtf8())
.pipe(splitLines())
.pipe(spy({ println("> $it") }))
.pipe(contents({
assertEquals(lines.size, it.size)
}))
}
where:
// doesn't handle lines split across buffers
fun splitLines() = transform<String, String> {
var count = 0
input.consumeEach {
it.split("\n").forEach {
output.send("${count++}: $it")
}
}
}
More in the tests…albertgao
04/06/2018, 2:23 AMonClick
is a clickHandler for a button
I try to get a result from a http get call.
But it only prints 1111
, not even prints 2222
. Not to mention the result. Simply just not there.
get function has been tested. It works. What am I missing here?user
04/06/2018, 2:41 AMuser
04/06/2018, 2:45 AMbg
function is not good choice for IO. bg
uses own fixed thread pool (2 * availableProcessors()
), so it make some sense, but usually for network you need more flexible thread strategy and also no sense to limit number of threads by CPU for IOuser
04/06/2018, 3:13 AMuser
04/06/2018, 3:20 AMbg
? Just check source code of bg, it’s just a wrapper function over async with predefined coroutine dispatcheruser
04/06/2018, 3:23 AMuser
04/06/2018, 3:23 AMKulwinder Singh
04/06/2018, 12:15 PMcoroutines
so is this code is ok .also i have read that async
will create new coroutine
each time so does it destroy coroutine
after work is finished or it will remain in memory ?user
04/06/2018, 12:19 PMdelay
method? instead of ugly contraption?altavir
04/06/2018, 12:20 PMuser
04/06/2018, 12:30 PMaltavir
04/06/2018, 12:42 PMuser
04/06/2018, 12:46 PMfun doAfter(seconds: Long, work: () -> Unit) {
launch(UI) {
delay(seconds)
work.invoke()
}
}
i have also changed funtions , so is it right now ?altavir
04/06/2018, 12:47 PMaltavir
04/06/2018, 12:48 PMaltavir
04/06/2018, 12:49 PMwork
is not suspended.