Open iskiselev opened 8 years ago
My preference is to introduce a tiny API in JSIL.Meta that you can use to write a WebWorker. When running in native C# the API will function using normal threads (maybe appdomains, if necessary), providing roughly the same semantics as a worker (as long as you don't break the rules). Then in the browser there will be an implementation of that in the JSIL libraries that does the necessary magic to spin up a worker and load your assemblies.
There's some stuff to nail down there, though - you need to make sure you pass all the JSIL.js configuration over (maybe some of it needs to be different in-worker?) and the compiler might need to yell at you when you do unsafe things.
Ideally if webworkers are instances of an abstract base class, the compiler itself can reject attempts to do unsafe things inside them, like reading static fields.
Why not use WebWorkers to do System.Threading.Tasks.Task.Run(...)
? That is/was my plan with CIL.JS
As to passing objects, You could do a remoteing/proxy system where the object only lives in the page.
It is possible already to run JSIL in WebWorker. It is also possible to run JSIL at the same time in main thread and WebWorker. I'd like to discuss any option for quick passing .Net object between WebWorkers and main thread, if JSIL with same types definitions loaded on both side. Easiest way for it will be serialize object, pass it and desalinize after it. Unfortunately serialization/deserializion is really slow process. Could we introduce some mechanics that will help as quickly create clear JSON data of object tree in one Worker and restore this tree in other worker? Probably, here I'm asking for something JSIL oriented special serilaizer - deserilaizer.
Or probably we could introduce something like proxies? Problem here is that we have not synchronous interactions with web workers.