Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JavaScript support #33

Closed
tristancaron opened this issue Mar 1, 2017 · 11 comments
Closed

JavaScript support #33

tristancaron opened this issue Mar 1, 2017 · 11 comments

Comments

@tristancaron
Copy link

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)
}
@elizarov
Copy link
Contributor

elizarov commented 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.

@musachy
Copy link

musachy commented Jul 24, 2017

Any ideas on when this might be implemented?

@elizarov
Copy link
Contributor

No specific timeline yet.

@epabst
Copy link

epabst commented Oct 15, 2017

I would really like this support... any update to the
timeline?

@elizarov
Copy link
Contributor

Stay tuned

@gzoritchak
Copy link

What does «Stay tuned» means?

It would be nice to give some piece of information. We have to plan how we develop our stuffs. Knowing an estimated date for a first version can help us taking decisions.

It's the oldest opened issue.

@elizarov
Copy link
Contributor

"Stay tuned" means we plan to do it. No specific date. We plan to do it as a multi-platform project from the very start, so we are currently waiting for 1.2 release with MP support.

@gzoritchak
Copy link

So with the 1.2 being quite close, we can expect it within reasonable time.

pull-vert pushed a commit to pull-vert/reactivity that referenced this issue Nov 20, 2017
… will be available as a common module (see Kotlin/kotlinx.coroutines#33) : kotlinx-coroutines and kotlinx-coroutines-reactive will be available as multiplatform projects (common + JS and JVM impl)
@pull-vert
Copy link

I'm waiting this multiplatform version too, for a multiplatform reactive stream library I'm writing (using a lot of kotlinx-coroutines-reactive stuff).

@elizarov if you want, I can fork this repository or you can create a branch from "develop" so I can start writing multiplatform version with 1.2 RC (only if it can be useful) ?

rivasdiaz added a commit to rivasdiaz/helloworld-chrome-extension-kotlin that referenced this issue Dec 18, 2017
@elizarov
Copy link
Contributor

Released in version 0.21

@Marcux83
Copy link

Marcux83 commented Jan 3, 2018

Sorry to open this again... but I just wanted to say:
You guys are truly awesome! Thank you for all you effort!
Im truly amazed by the vision you are bringing to life here.
Will support you from Vienna by participating in regular Kotlin-Meetups and of course by using your products <3

@pull-vert pull-vert mentioned this issue Jan 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants