Skip to content

Add JS as a target for kmp-nativecoroutines-core #48

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

Merged

Conversation

ankushg
Copy link
Contributor

@ankushg ankushg commented Feb 22, 2022

Part of #17 and #43

Doesn't add update any of KSP, but implements all expects and gets tests passing for JS 😄

@ankushg ankushg mentioned this pull request Feb 22, 2022
26 tasks
@ankushg
Copy link
Contributor Author

ankushg commented Feb 22, 2022

@rickclephas Not sure if you want to merge this individually or wait until we add the logic to KSP

IMO merging it now makes sense so we can make sure things don't drift too much as other changes get merged


@Suppress("SuspendFunctionOnCoroutineScope")
internal actual suspend fun CoroutineScope.runCurrent() {
coroutineContext[Job]?.children?.forEach { it.join() }
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we should use runCurrent from the TestScope, so I guess we could just define it in commonMain with a type check on the CoroutineScope instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done (with the typecheck in nativeCoroutinesMain)

@ankushg ankushg requested a review from rickclephas February 23, 2022 18:34
Copy link
Owner

@rickclephas rickclephas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm looks like the coroutines-test classes aren't working as expected on JS 🤔

@ankushg
Copy link
Contributor Author

ankushg commented Feb 23, 2022

Hmm looks like the coroutines-test classes aren't working as expected on JS 🤔

Hmm it was green before switching JS from coroutineContext[Job]?.children?.forEach { it.join() } to runCurrent

@ankushg
Copy link
Contributor Author

ankushg commented Mar 3, 2022

@rickclephas I figured it out! runCurrent runs the tasks that are pending for the current virtual timestep, but doesn't run any tasks that would be running in a future time step, even if they're already queued up.

What we really want to do is run all pending tasks, and keep advancing until there are no more tasks left to run. advanceUntilIdle looks like it's designed to do that 😄

Replacing runCurrent() with advanceUntilIdle() fixes the JS tests

@rickclephas rickclephas changed the base branch from master to feature/GH-17-js-support March 4, 2022 18:18
@rickclephas rickclephas merged commit 4dd7363 into rickclephas:feature/GH-17-js-support Mar 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants