BearDev
07/09/2020, 6:53 AMprivate external var postMessage: dynamic
data class MessageToMain(
val text: String
)
fun testInWorker() {
val message = MessageToMain("Hello world!")
postMessage(message)
}
And here's code that is ran in the main js thread:
worker.onmessage = {
val data = it.data
console.log(data)
val typed = data as MessageToMain
println(typed)
Unit
}
console.log outputs {text: "Hello world!"}
, but trying to cast it to MessageToMain unsurprisingly results in ClassCastException
being thrown. Considering that the actual javascript object in data
should satisfy the class definition of MessageToMain, I am wondering if there is a way to forcefully cast it.patrickdelconte
07/09/2020, 7:41 AMexternal interface
for the messagesBearDev
07/09/2020, 8:02 AMturansky
07/09/2020, 10:27 AMBearDev
07/09/2020, 10:34 AM