-
-
Notifications
You must be signed in to change notification settings - Fork 565
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
Promise not resolving, if resolve() invoked from C# callback function #1576
Comments
Jint doesn't support multi-threading and that's what your Task.Delay is doing. |
Is there some alternative solution how to resume js code execution after c#? As far I understrand it's quite popular problem (fetch, setTimeout, etc...) |
I think this would need some investigation and hopefully a PR that would both include tests and a remedy 😉 |
For me, new Promise(function (resolve) {
log('Promise!')
resolve(null)
}).then(function () {
log('Resolved!')
}) Expected output:
Actual output:
|
Can confirm the behavior is still the same as of 3.0 |
You can use c# tasks, they are converted to promises and awaited correctly. so looking at the first example here, this would work: using Jint;
using System;
using System.Threading.Tasks;
var engine = new Engine();
engine.SetValue("log", new Action<object>(Console.WriteLine));
engine.SetValue("setTimeout", new Func<int, Task>(setTimeout));
engine.Evaluate(@"
setTimeout(10000)
.then(res => {
log('resolved');
})
.catch(res => {
log('rejected');
})
;
");
async Task setTimeout(int delay)
{
await Task.Delay(delay).ConfigureAwait(false);
} Just your standard C# and JS async/await way of working :) I prefer to write it like this: var engine = new Engine();
engine.SetValue("log", new Action<object>(Console.WriteLine));
engine.SetValue("setTimeout", new Func<int, Task>(setTimeout));
engine.Evaluate(@"
(async () => {
await setTimeout(1000);
log('resolved');
})();
");
async Task setTimeout(int delay)
{
await Task.Delay(delay).ConfigureAwait(false);
} |
Version used
v3.0.0-beta-2049
Describe the bug
Promise not resolving, if resolve() invoked from C# callback function.
To Reproduce
GIST: https://gist.github.com/Dubiy/a761662f95341bc530574dec9f29e02a
Or code:
Expected behavior
Actual behavior
The text was updated successfully, but these errors were encountered: