feat: add await function to promise

This commit is contained in:
TopchetoEU 2023-11-25 18:47:51 +02:00
parent e107dd3507
commit 443dc0ffa1
Signed by: topchetoeu
GPG Key ID: 6531B8583E5F6ED4

View File

@ -347,4 +347,19 @@ import me.topchetoeu.jscript.interop.Native;
public PromiseLib() { public PromiseLib() {
this(STATE_PENDING, null); this(STATE_PENDING, null);
} }
public static PromiseLib await(Context ctx, PromiseRunner runner) {
var res = new PromiseLib();
new Thread(() -> {
try {
res.fulfill(ctx, runner.run());
}
catch (EngineException e) {
res.reject(ctx, e.value);
}
}, "Promisifier").start();
return res;
}
} }