Skip to content
This repository has been archived by the owner on Dec 10, 2022. It is now read-only.

Implement java Threads in single-threaded targets like JS, Dart, PHP and so on #265

Open
soywiz opened this issue Aug 26, 2017 · 0 comments
Milestone

Comments

@soywiz
Copy link
Member

soywiz commented Aug 26, 2017

After 1.0, I'd like to implement threads in all targets including single-threaded, event-loop-based, asynchronous targets. This is not going to implement soon, to avoid making noise to other things that are more important like supporting java8 and java9, and implementing all the API (except complex things like awt and things like that).

The idea is to mark I/O, sleeping and synchronization methods as suspension points, with a continuation implementation (for example Thread.sleep : @JTranscAsyncMethod(target = "js", value ="setTimeout(continuation, p0);")), then rewrite each method that can produce a suspension or call a method hierarchy that could lead to a suspension, so it is converted into a while + switch loop (like it is already), but moving all local variables including state variable into a struct, so we can exit the method and resume it later. Just like does C# async, and Kotlin coroutines.

This would allow to write plain java with threads, synchronous I/O and so on, so it works on ALL targets including JS while using asynchronous APIs and a single-threaded event loop.

@soywiz soywiz added this to the 1.1.0 milestone Aug 26, 2017
@soywiz soywiz mentioned this issue Oct 15, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant