Skip to content
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

Documentation: await all unsettled promises after Context.Run #202

Open
viceice opened this issue Jan 17, 2020 · 5 comments
Open

Documentation: await all unsettled promises after Context.Run #202

viceice opened this issue Jan 17, 2020 · 5 comments

Comments

@viceice
Copy link
Contributor

viceice commented Jan 17, 2020

How do I await all unsettled promises after Context.Run()?

js code

(async () => {
  await Promise.resolve();
  throw new Error('test');
})();

console.log('after');

cs code

var ctx = new Context();
ctx.Eval("<js code>");
// ctx.WaitForPromises() -> should throw on unhandled rejections
@viceice viceice changed the title await all unsettled promises after Context.Run Documentation: await all unsettled promises after Context.Run Jan 17, 2020
@nilproject
Copy link
Owner

There is currently no way to do this. Promise is a simple wrapper for Task. There is no object in which all created Promises are stored for a number of reasons. You can make your own solution for this.

@viceice
Copy link
Contributor Author

viceice commented Nov 9, 2021

Can the promises cause multi threading issues? eg when i create a list of them and await them all? Are they guaranteed to not run on seperate threads, like in nodejs, where we only have a single thread?

@nilproject
Copy link
Owner

nilproject commented Nov 9, 2021

It sounds not good, but no, we have no guarantees. Each promise will be evaluated in separate thread. This is because Promise in current implementation is just a wrapper for System.Threading.Tasks.Task.
Yes, promises can cause some multi threading issues

@viceice
Copy link
Contributor Author

viceice commented Nov 9, 2021

And i can't override the Promise implementation, as it's pretty hard wired. 😕

@nilproject
Copy link
Owner

nilproject commented Nov 9, 2021

So, lets fix this.
Please, look at #262. Is it possible to override Promise after these changes?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants