How would I go from a suspending function to a Promise or just getting rid of the suspend completely? (on the JVM, you would use runBlocking for example)
My submit function is using Coroutines, but I want to JsExport the functions making use of the submit function
class POST(
val uri: String,
val json: String,
) {
suspend fun <T> submit(): T {
return window.fetch(
input = "${ENV.server}$uri",
init = RequestInit(
body = json,
method = "POST",
headers = json("content-type" to "application/json; charset=UTF-8"),
)
).await().json().await().unsafeCast<T>()
}
}
@JsExport
@ExperimentalJsExport
object Data {
suspend fun getColumns(request: ColumnRequestVO): ColumnResponseVO {
return POST(uri = "/columns", json = request.toString()).submit<ColumnResponseVO>()
}
}
Declaration of such kind (suspend function) cant be exported to JS