coder82
07/03/2018, 8:39 AMdekans
07/03/2018, 9:09 AMoffer
coder82
07/03/2018, 9:25 AMcoder82
07/04/2018, 7:36 AMcoder82
07/04/2018, 7:36 AMcoder82
07/04/2018, 8:22 AMredrield
07/07/2018, 8:43 PMredrield
07/07/2018, 9:03 PMdekans
07/07/2018, 10:34 PMnoncom
07/10/2018, 1:47 PMfun
with suspend
noncom
07/10/2018, 1:47 PMrocketraman
07/10/2018, 5:17 PMfun main(args: Array<String>) = runBlocking {
fun log(msg: String) = println("[${Thread.currentThread().name}] $msg")
newSingleThreadContext("SINGLE-THREAD").use {
launch(it) {
log("Running in single-thread context.")
withContext(CommonPool) {
log("Running in CommonPool context.")
}
log("Should be back to running in single-thread context?")
}
}.join()
}
prints:
[SINGLE-THREAD @coroutine#2] Running in single-thread context.
[ForkJoinPool.commonPool-worker-25 @coroutine#2] Running in CommonPool context.
[kotlinx.coroutines.DefaultExecutor @coroutine#2] Should be back to running in single-thread context?
nwh
07/10/2018, 11:20 PMval DB = Executors.newCachedThreadPool(object : ThreadFactory {
var i = 0
override fun newThread(r: Runnable?) = Thread("db-${i++}")
}).asCoroutineDispatcher()
If I use it like this:
launch(DB) {
val records = ...;
// A
}
Will code in A
be tying up threads from the dispatcher?rocketraman
07/11/2018, 12:36 AMrocketraman
07/11/2018, 12:37 AMigorvd
07/11/2018, 12:58 PMWorker
expects a return value, so I can't just use the launch
dispatcher.
I'm using the runBlocking
dispatcher to be able to call the suspend functions... Is this the right way to go?
Here's an example:
override fun doWork(): Result = runBlocking {
//call some suspend functions
return Result.SUCCESS
}
Thanks!jw
07/11/2018, 12:59 PMigorvd
07/11/2018, 1:01 PMgroostav
07/13/2018, 5:23 AMMutex
class in kotlinx.coroutines preseves locking order? In other words, if two jobs get suspended on a mutex, when the mutex is released will the first job to acquire the lock always go first?groostav
07/13/2018, 5:24 AMLockedQueue
, which implies queueing behaviour...nwh
07/18/2018, 5:35 PMwithoutclass
07/18/2018, 5:36 PMnwh
07/18/2018, 5:38 PMwithoutclass
07/18/2018, 5:39 PMnwh
07/18/2018, 5:46 PMimage.png▾
user
07/18/2018, 5:46 PMuser
07/18/2018, 5:55 PMuser
07/18/2018, 5:56 PMgroostav
07/19/2018, 10:55 PMgroostav
07/19/2018, 10:57 PMclass MyServiceObjectThatMakesDBQueryAtInitialization(db: AsyncMap<UUID, Model>) {
val modelObject = fastSuspendingInitializer { db.lookupInitialValue(key) }
}