JavaScript support
See original GitHub issueAny plan about to include JavaScript specifications into the library?
It could be great to make this library as a reference.
import org.w3c.fetch.Response
import kotlin.coroutines.experimental.*
import kotlin.js.Promise
external fun fetch(url: String): Promise<Response> = definedExternally
suspend fun <T> Promise<T>.await(): T = suspendCoroutine {
then(it::resume).catch(it::resumeWithException)
}
fun <T> async(block: suspend () -> T) = Promise<T> { resolve, reject ->
block.startCoroutine(completion = object : Continuation<T> {
override val context: CoroutineContext = EmptyCoroutineContext
override fun resume(value: T) {
resolve(value)
}
override fun resumeWithException(exception: Throwable) {
reject(exception)
}
})
}
}
fun asyncTest() = async {
val value = fetch("./test.txt").then(Response::text).await()
println(value)
}
Issue Analytics
- State:
- Created 7 years ago
- Reactions:2
- Comments:11 (5 by maintainers)
Top Results From Across the Web
Browser support for JavaScript APIs - Mozilla - MDN Web Docs
Browser support for JavaScript APIs. action. Report problems with this compatibility data on GitHub. desktop, mobile. Chrome. Edge. Firefox. Opera. Safari.
Read more >How to enable JavaScript in your browser and why
We want your visitors to have JavaScript enabled just as much as you do! Google Chrome. On the web browser menu click on...
Read more >"javascript" | Can I use... Support tables for HTML5, CSS3, etc
"Can I use" provides up-to-date browser support tables for support of front-end web technologies on desktop and mobile web browsers.
Read more >Activate JavaScript in your browser - Google AdSense Help
Activate JavaScript in Google Chrome · Open Chrome on your computer. · Click More and then Settings. · Click Security and Privacy. ·...
Read more >Enabling JavaScript in Browsers - Tutorialspoint
This chapter explains the procedure of enabling and disabling JavaScript support in your browsers: Internet Explorer, Firefox, chrome, and Opera.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yes. There is a plan to have a subset of
kotlix-coroutines-core
module available in JS and to provide additional utility functions for JSPromise
.Released in version 0.21