Skip to content

Kotlin Coroutines support? #2

Closed
@linux-china

Description

@linux-china

Upgrade worker to Kotlin 1.4.0 and all is good. But failed to run worker with kotlinx:kotlinx-coroutines-core-js. Cloudflare runtime compatible problem or my code problem?

build.gradle.kts:

    implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core-js:1.3.9")

Example code:

import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.promise
import org.w3c.fetch.Response
import org.w3c.fetch.ResponseInit
import org.w3c.workers.FetchEvent

fun main() {
    addEventListener("fetch") { event: FetchEvent ->
        event.respondWith(handleEvent(event))
    }
}

fun handleEvent(event: FetchEvent) = GlobalScope.promise {
    val headers: dynamic = object {}
    headers["content-type"] = "text/plain"
    Response(
        "Hello Kotlin Worker",
        ResponseInit(headers = headers)
    )
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions