-
Notifications
You must be signed in to change notification settings - Fork 376
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
Support prim__fork on javascript #1238
Conversation
Maybe this should be the browser-specific way of implementing fork. That would mean using the "browser" FFI tag instead of "javascript". We can do better for Node than just a timeout, right? If nothing else forking via spawning a child process should be possible so I think a simple 0 second timeout for a fork in Node is a bit misleading. |
Thanks for the review. I've looked into it, and while In fact, Nodejs has process.nextTick and setImmediate. These are not supported on most browsers and I haven't found any advantage that would make differing runtime behavior on browser/node worthwhile. The best API to use here would be queueMicrotask because it is fast and predictable, but not universally supported. However, Promises are almost universally supported and internally use the same mechanism. For CPU-bound uses, web workers and node workers implement threads but have a different api and communicate via postMessage and such. They may have a place as an Idris library, but not as the main concurrency primitive. From Node API docs:
A mechanism for overriding FFI implementations, or interface-based reflection of backend type like in Idris1 could also be handy. So.. I'll update the PR with an implementation that uses promises. Let me know what you think. |
Regarding |
I thought that |
according to https://idris2.readthedocs.io/en/latest/backends/javascript.html#javascript-ffi-specifiers |
You've now done a lot more research into this than me! I defer to you at this point. All of your notes make sense to me, though. |
Is this still the plan? |
Yeah. I wanted to add some tests too. |
I'm still on this but I ran into infinite loops while testing (trying to implement a http server and using |
This seems to still be a draft and discussion has stopped - so I'm going to close it for tidiness but please feel free to reopen if the details are rseolved. |
When trying to use
PrimIO e => App e r
on javascript, the following error is thrown:I worked around it with a separate PrimIO instance which I had to then use everywhere. Implementing fork is a better solution.
In this PR, I added a javascript foreign implementation for
prim__fork
usingsetTimeout
. ImplementingwaitThread
on a timeout is not possible, but would be of arguably limited use in js (withoutasync
).With this small change, it becomes possible to do
PrimIO
inApp
on javascript.