lukaswelte
10/15/2018, 6:45 AMContinuation
in detail. Can someone recommend some good resources on the topic?otakusenpai
10/15/2018, 12:45 PMfun runBots() = runBlocking {
try {
bots.forEach {
val one = launch { it.value.setConnection(); }
one.join()
delay(3000L)
if(it.value.running) {
it.value.Connect()
}
}
} catch(e: Throwable) {
bots.forEach { if(!it.value.running) it.value.Connect() }
}
}
"bots" here is the map of strings to bots. Each bot has a Connect() function(a async function) which runs the all the bot's main loop. The problem is that the bot doesnt run, after the server class calls it's runBots function.
Initialised
Connnected: true
Defined bot
Added bot
[main] Connecting....
[main] Sending nick...
Sending nick: NICK Kraken3635
[main] Sending user...
Sending user: USER Nani 0 * :Nani
[main] Connected!
[DefaultDispatcher-worker-1] I'm now in Connect!
[DefaultDispatcher-worker-1] Entering loop...
enleur
10/15/2018, 1:32 PMCoroutineScope
extensions, but I think it should be also in docsgildor
10/15/2018, 1:51 PMitnoles
10/15/2018, 2:53 PMotakusenpai
10/15/2018, 4:30 PMsuspend fun addEvent(value: MsgType): Event {
val eventChannel = Channel<Event>()
var event: Event? = null
log("joining", logMessages)
if (value == MsgType.ping) {
log("ping", logMessages)
eventChannel.send(PingEvent(value) as Event)
}
else if (value == MsgType.join) {
log("join", logMessages)
eventChannel.send(JoinEvent(value) as Event)
}
else if (value == MsgType.normal) {
log("normal", logMessages)
eventChannel.send(NormalEvent(value) as Event)
}
else if (value == MsgType.privmsg) {
log("privmsg", logMessages)
eventChannel.send(PrivMsgEvent(value) as Event)
}
else if (value == MsgType.mode) {
log("mode", logMessages)
eventChannel.send(ModeEvent(value) as Event)
}
else if (value == MsgType.notice) {
log("notice", logMessages)
eventChannel.send(NoticeEvent(value) as Event)
}
else if (value == MsgType.special) {
log("special", logMessages)
eventChannel.send(SpecialEvent(value) as Event)
}
else if (value == MsgType.namelist) {
log("namelist", logMessages)
eventChannel.send(NameListEvent(value) as Event)
}
else if (value == MsgType.topic) {
log("topic", logMessages)
eventChannel.send(TopicEvent(value) as Event)
}
else if (value == MsgType.topic_whotime) {
log("whotime", logMessages)
eventChannel.send(TopicWhoTimeEvent(value) as Event)
}
else if (value == MsgType.quit) {
log("quit", logMessages)
eventChannel.send(QuitEvent(value) as Event)
}
else if (value == MsgType.who) {
log("who", logMessages)
eventChannel.send(WhoEvent(value) as Event)
}
else if (value == MsgType.end_of_who) {
log("end of who", logMessages)
eventChannel.send(EndOfWhoEvent(value) as Event)
}
log("receiving", logMessages)
event = eventChannel.receive()
log("received", logMessages)
if(event == null)
throw AghoraException("Error: In addEvent(value: MsgType): Event in " +
" com.github.otakusenpai.aghora.irc: No implementation of MsgType ${value.toString()}")
log("returning", logMessages)
return event
}
Can anyone explain why this code isnt returning the value from the Channel ?claudiug
10/15/2018, 6:29 PMclaudiug
10/15/2018, 6:30 PMRuckus
10/15/2018, 7:37 PMonReceiveOrNull
doesn't really work if I have multiple channels and want the rest to continue if any of them close (as select
is biased to the first).digitalsanctum
10/15/2018, 7:55 PMJoeHegarty
10/15/2018, 9:08 PMdigitalsanctum
10/15/2018, 10:03 PMdave08
10/16/2018, 3:15 AMclass MainPresenter : CoroutineScope by CoroutineScope(Dispatchers.Main)
to get rid of a bit of boilerplate, just missing an easy way to access its Job to cancel it on the end of its lifecycle...?oshai
10/16/2018, 7:12 AMrobin
10/16/2018, 3:01 PMsuspend fun main(args: Array<String>) = runBlocking {
val unsorted = generateSequence { Random.nextInt() }.take(200)
val sortedChannel = Channel<Int>()
val sorted = sequence { for (msg in sortedChannel) yield(msg) }
unsorted.map { async { delay(it * 10L); sortedChannel.send(it) } }
sorted.forEach(::println)
}
But I'm getting an error about restricted suspending functions where I'm iterating over the channel. Can anyone tell me what that's about?Robert Menke
10/16/2018, 3:32 PMcancel
method. I’m working on creating a class that implements CoroutineScope
and I’m following the example here https://github.com/Kotlin/kotlinx.coroutines/blob/master/core/kotlinx-coroutines-core/test/guide/example-context-10.kt.
I would expect that job.cancel()
would return true in this case since the invocation of cancel is what cancels the job, however, when I print the result of job.cancel()
I get false.
fun destroy() {
val temp = job.cancel()
print(temp.toString()) //prints "false" even though I would expect it to print "true"
}
Am I misunderstanding cancel?Zach Klippenstein (he/him) [MOD]
10/16/2018, 3:57 PMDias
10/16/2018, 5:06 PMlaunch {
launch {
throw RuntimeException()
}
while (true) {
println("123123")
}
}
I want parent launch to exit with an exception, but not sure how toAllan Wang
10/16/2018, 6:04 PMhttps://www.youtube.com/watch?v=a3agLJQ6vt8▾
CancellationException
will cancel the parent no matter what, so do we have to wrap our code in a try catch?
To be more specific, this is the problem I want to solve:
I have a method that takes in an id and returns an auth object
I have other methods that will take in an auth object and then output something else
I want to create a running stream for the duration of my lifecycle that will take in ids and actions. If an auth does not exist (say in a map), I want to fetch it. Once an auth is fetched, I want to run any pending actions on that auth. If an auth is being fetched and another request is made requiring that auth, it should wait for the previous fetch rather than getting a new auth itself. This pattern is already shown in the talk using Map<T, List<K>>
. If the auth fetch fails, I want to cancel any pending actions. If an action fails, or anything else outside of this scope, I want the CoroutineScope
to stay alive, until it is cancelled by the lifecycle.Slackbot
10/16/2018, 8:35 PMgroostav
10/17/2018, 12:12 AMgroostav
10/17/2018, 12:12 AMscope
?myanmarking
10/17/2018, 10:27 AMjava.lang.IllegalStateException: Module with the Main dispatcher is missing. Add dependency providing the Main dispatcher
release builds onlyJonathan
10/17/2018, 11:52 AMvoddan
10/17/2018, 12:19 PMasync {}
block throws an exception, but the result is never used? I get different behaviour in playground and InteliJ
https://pl.kotl.in/rkOAdiNiQ
suspend fun main() {
coroutineScope {
val x = async { null!! }
}
println("end")
}
antoin_m
10/17/2018, 1:45 PMtw
10/17/2018, 1:53 PMantoin_m
10/17/2018, 1:59 PMspierce7
10/17/2018, 3:38 PMenleur
10/17/2018, 9:00 PMenleur
10/17/2018, 9:00 PMPaul Woitaschek
10/17/2018, 9:09 PMenleur
10/17/2018, 9:10 PMPaul Woitaschek
10/17/2018, 9:10 PMenleur
10/17/2018, 9:16 PMVsevolod Tolstopyatov [JB]
10/18/2018, 8:02 AM