question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

JavaScript support

See original GitHub issue

Any 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:closed
  • Created 7 years ago
  • Reactions:2
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

20reactions
elizarovcommented, Mar 1, 2017

Yes. There is a plan to have a subset of kotlix-coroutines-core module available in JS and to provide additional utility functions for JS Promise.

15reactions
elizarovcommented, Dec 28, 2017

Released in version 0.21

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found