otakusenpai
10/17/2018, 9:00 PMdanny
10/18/2018, 12:27 AM<http://Dispatchers.IO|Dispatchers.IO>
? I'm seeing different behavior to the documentation, and some scheduling weirdnessoshai
10/18/2018, 5:35 AMSUPERCILEX
10/18/2018, 5:59 AMSUPERCILEX
10/18/2018, 5:59 AMSUPERCILEX
10/18/2018, 5:59 AMSUPERCILEX
10/18/2018, 5:59 AMSUPERCILEX
10/18/2018, 6:02 AMSUPERCILEX
10/18/2018, 6:06 AMmarcinmoskala
10/18/2018, 12:34 PMdave08
10/18/2018, 2:21 PMsupervisorScope { }
and coroutineScope { }
get their CoroutineScope
from?dave08
10/18/2018, 3:43 PMproduce { }
that sends download status to a notification service, so if there's an exceoption I'd like to be able to send an error message. It looks like try { } catch() { }
is unreliable (https://github.com/Kotlin/kotlinx.coroutines/issues/361), and installing a CoroutineExceptionHandler
on produce
I won't be able to get to its channel to report status... is there any better way to do this?SUPERCILEX
10/18/2018, 4:51 PMpublic suspend inline fun <T : Closeable?, R> T.useCancellably(
crossinline block: (T) -> R
): R = suspendCancellableCoroutine { cont ->
cont.invokeOnCancellation { this?.close() }
use(block)
}
danny
10/18/2018, 7:14 PMotakusenpai
10/19/2018, 3:22 AMclass AsyncLogger : AbstractLogger {
constructor(filepath: String,name: String) : super() {
var file = File(filepath)
file.mkdirs()
filename = "$filepath/$name"
file = File(filename)
}
suspend fun log(toLog: Boolean,msg: String) = coroutineScope {
GlobalScope.launch {
if (toLog)
writeToFile(msg)
}
}
suspend fun log(toLog: Boolean,toFile: Boolean,msg: String) = coroutineScope {
GlobalScope.launch {
if(toLog)
when(toFile) {
true -> writeToFile(msg)
false -> writeToFile(msg)
}
}
}
override suspend fun writeToSTDOUT(msg: String) =
println(message = "[${Thread.currentThread().name}]: $msg")
override suspend fun writeToFile(msg: String): Job = coroutineScope {
GlobalScope.launch {
val stream = RandomAccessFile(filename, "rw")
val channel = stream.channel
var lock: FileLock? = null
try {
lock = channel.tryLock()
} catch (e: OverlappingFileLockException) {
stream.close()
channel.close()
}
stream.writeBytes(msg + '\n')
lock?.release()
stream.close()
channel.close()
}
}
}
otakusenpai
10/19/2018, 6:05 AMSUPERCILEX
10/19/2018, 7:44 AMjoin
now that the outer scope will wait for all functions launched within to complete?otakusenpai
10/19/2018, 7:48 AMotakusenpai
10/19/2018, 7:55 AMJoris PZ
10/19/2018, 8:20 AM.receive()
on a non-blocking NIO channel, it will immediately return with either some available data, or null
. So if I were to use this in a coroutine, I'd have to do this in an infinite loop, no? Something like:
while(true) {
channel.receive(buffer)
// handle data if available
}
If I were to implement it like this, wouldn't that make the CPU load 100%? Or am I supposed to implement a delay here to prevent this?alex009
10/19/2018, 9:06 AMDaniel Tam
10/19/2018, 11:56 AMRuckus
10/19/2018, 5:58 PMmyanmarking
10/19/2018, 6:15 PMmyanmarking
10/19/2018, 6:15 PMDamien
10/19/2018, 8:16 PMpabl0rg
10/20/2018, 10:44 AMraulraja
10/20/2018, 8:52 PMw: -Xcoroutines has no effect: coroutines are enabled anyway in 1.3 and beyond
I’m not sure where to disable it as I don’t have manual flags passed to the compiler process. Any help is appreciated, thanks!oshai
10/20/2018, 8:58 PMNikky
10/21/2018, 11:22 AMNikky
10/21/2018, 11:22 AMkevinherron
10/22/2018, 4:21 AM