ByFloRedstone
11/30/2020, 5:45 PMbbaldino
11/30/2020, 5:50 PMByFloRedstone
11/30/2020, 5:53 PMbbaldino
11/30/2020, 5:55 PMByFloRedstone
11/30/2020, 5:58 PMbbaldino
11/30/2020, 5:59 PMsend
method to wait until the message is sent, you can run it within a runBlocking
block. If you don't want to wait, you'll want to use launch
on some CoroutineScope
to launch a coroutine to do the sendByFloRedstone
11/30/2020, 6:00 PMbbaldino
11/30/2020, 6:01 PMGlobalScope
, for example, but I don't think it's recommended to use that except for specific use cases as tasks launched there can 'leak'.bbaldino
11/30/2020, 6:02 PMCoroutineScope
ByFloRedstone
11/30/2020, 6:02 PMbbaldino
11/30/2020, 6:03 PMByFloRedstone
11/30/2020, 6:30 PMbbaldino
11/30/2020, 6:31 PMByFloRedstone
11/30/2020, 6:45 PMbbaldino
11/30/2020, 6:46 PMByFloRedstone
11/30/2020, 6:48 PMbbaldino
11/30/2020, 6:48 PMByFloRedstone
11/30/2020, 6:48 PM@EventListener
fun onStart(e: CloudServicePreStartEvent) {
sendNotification(SocketNotification("success", "Der Service ${e.cloudService.serviceId.name} startet"))
}
fun sendNotification(notification: SocketNotification) {
webServer.notificationSockets.forEach {
runBlocking { it.send(Frame.Text(notification.toString())) }
}
}
ByFloRedstone
11/30/2020, 6:49 PMbbaldino
11/30/2020, 6:50 PMrunBlocking
block in sendNotification
was called 6 times?ByFloRedstone
11/30/2020, 6:52 PMbbaldino
11/30/2020, 6:53 PMsend
is "finishing" each time it's called ?ByFloRedstone
11/30/2020, 6:55 PMByFloRedstone
11/30/2020, 6:56 PMlet socket = new WebSocket("<wss://acp.domain.com/ws>")
socket.onopen = function (event) {
log("info", "Connected to the Notify Socket")
}
socket.onerror = function (error) {
log("error", error.message)
}
socket.onmessage = function (m) {
log("message", m.data)
}
function log(type, input) {
console.log("[NOTIFY] " + type.toUpperCase() + " | " + input)
}
bbaldino
11/30/2020, 6:56 PMByFloRedstone
11/30/2020, 6:58 PMbbaldino
11/30/2020, 7:08 PM