deviant
03/08/2019, 3:02 PMprivate suspend fun <E> ReceiveChannel<E>.throttle(): ReceiveChannel<E> {
// want to launch {} in current scope
}
withoutclass
03/08/2019, 3:20 PMthrottle
, then use that scope to launch
deviant
03/08/2019, 3:42 PMsitepodmatt
03/08/2019, 3:49 PMdeviant
03/08/2019, 3:51 PMpublic suspend fun <R> coroutineScope(block: suspend CoroutineScope.() -> R): R
and i would like to run the launch
in worker threadsitepodmatt
03/08/2019, 3:52 PMdeviant
03/08/2019, 3:54 PMval scope = CoroutineScope(Dispatchers.Default)
scope.launch(Dispatchers.Default) {...}
sitepodmatt
03/08/2019, 3:54 PMCoroutineScope(coroutineContext).run {
launch {
}
}`
deviant
03/08/2019, 3:55 PMI recall they dont recommend this waydo you know why?
sitepodmatt
03/08/2019, 3:56 PMgildor
03/09/2019, 12:01 AMnot very convenientThis is the most explicit and safe way, because caller knows exactly on which scope new coroutine will be executed, now instead you create new scope that uses job of parent But I would say that for this particular use case it's probably fine to make this channel`s operator signature clear
elizarov
03/09/2019, 9:42 AM