Checking if a returned promise is complete #935
Replies: 3 comments 32 replies
-
Converted to discussion and pinging @twop for possible insights and ideas. |
Beta Was this translation helpful? Give feedback.
-
Happy to elaborate! The fundamental difference between Task and Promise is that Promise assumes a single threaded EventLoop while Task has a luxury to have an extra feature of multithreading and be more flexible in terms of runtime (no EventLoop). In other words, you HAVE to think through if and how you need to synchronize Tasks, while Promises are inherently sequential via EventLoop. But I totally agree with you that they have more in common than different, but the devil in the details which are very relevant in the context of JS engine implementation.
Absolutely spot on! When you run
Note that Btw that is almost exactly how I use Jint Promises in my project. I think conceptually you can think about it as of mapping Task + .NET runtime scheduling to JS EventLoop. Does it make it clearer or even more confusing? |
Beta Was this translation helpful? Give feedback.
-
Good find! It used to be two functions |
Beta Was this translation helpful? Give feedback.
-
Hi all,
I just started messing around with the new Promise API and had a quick question.
in the following example
obj.SimpleTask
is a CLR function returning a task, I have written a custom object converter to swap that to an object. The purpose of the function is to wait for a second and then return a random number, simulating IO work.When I run the program, I get the following exception:
When I add a delay that exceeds the duration of the original wait, as in the following, I am able to extract the result, (in this case 'done') from the promise.
So far I haven't been able to find a way to check if the promise that has been extracted from the engine has resolved. When I looked in to
UnwrapIfPromise()
I saw that there is a promise state object, but withPromiseInstance
being an internal class I can't do a type cast to monitor those values.I'm assuming that I'm probably just missing something, so if any of you have any idea how to check a promise's status let me know.
Thanks in advance!
Beta Was this translation helpful? Give feedback.
All reactions