Event Loop and async code #1081
Replies: 4 comments 6 replies
-
Let' not forget that JavaScript is single-threaded 😉 , but pinging subject matter expert @twop for insights into discussion. |
Beta Was this translation helpful? Give feedback.
-
Maybe I'm missing something but you can do that today with So today this workflow is possible:
So in short, you can execute promises in whatever thread you wish with whatever async primitives are available to you, BUT you need to continue execution (when you fulfill them) on the same thread. I think I wrote a helper that does exactly that a while back, that does all the steps and works on top of existing API (e.g. can be done completely outside of Jint). @lahma do you remember where that snippet was? I acknowledge that following these steps can be tedious, but remember that |
Beta Was this translation helpful? Give feedback.
-
On other points you made such as
When I was working on adding Promises my goal was to ship MVP, I believe the current version might have rough edges in terms of tracking and timeouts. Specifically because fulfilling promises are essentially the same as calling |
Beta Was this translation helpful? Give feedback.
-
Related discussions: #935 Also found a snippet that I made a while back: https://gist.github.com/twop/8d7b849d0105c779eed87bff8ae59722 Note that the code in the snippet is designed to live outside of Jint core. Thus feel free to copy and modify directly into your project. If I recall correctly @lahma wanted to take it and package it as a separate NuGet. Am I dreaming that this conversation happened ^_^ ? |
Beta Was this translation helpful? Give feedback.
-
Hi,
I think the idea with the event loop is the chance to make jint somehow ready for the async world. I am not talking about async-await just about some code that is invoked later when a condition has been met.
I am talking about callbacks, promises and real async/await code. I try to understand how promises work, but I have my problems with that. Therefore I am trying to start from beginning.
At the moment, the execution mode of jint is linear. Therefore when
Execute
returns we assume that all code that should have been run has been executed. Of course this does not work with callbacks anymore, so we need a way to define when we are done.For my understanding we are done when all jobs in the event loop have been executed successfully. We could create an async method for that and just complete a TaskCompletionSource when the event loop is empty.
The idea of the event loop should be to schedule some code to be executed at a later point of time. When the code is executed, is the responsibility of the extension or function that uses delegates.
If I understand it properly this is exactly how RegisterPromise works.
But I see a few problems or questions:
Beta Was this translation helpful? Give feedback.
All reactions