Closed anuragvohraec closed 1 year ago
The resolving_funcs
parameter takes an array of functions: [then, catch].
The
resolving_funcs
parameter takes an array of functions: [then, catch].
Thank you. And sorry if I am asking too basic questions.
I have even gone through the source code to understand this, but from source code it seemed that it only supported two functions(which I guessed are resolve
and reject
):
static JSValue js_new_promise_capability(JSContext *ctx, JSValue *resolving_funcs, JSValueConst ctor){
//some code
//line 46699
for(i = 0; i < 2; i++)
resolving_funcs[i] = JS_DupValue(ctx, s->data[i]);
//some code
}
And hence the confusion.
Now if these were then
and catch
, then how do one resolve or reject a promise ?
ok so exploring github + stackoverflow, here is the overall conclusion for future referce for any one.
JS_NewPromiseCapability
to create a promise.resolving_funcs
are the resolve and reject function.promise
object. And do JS_Call
to pass callbacks to them.ok so exploring github + stackoverflow, here is the overall conclusion for future referce for any one.
- Use
JS_NewPromiseCapability
to create a promise.- The param
resolving_funcs
are the resolve and reject function.- To pass then and catch callbacks, treat them as properties on
promise
object. And doJS_Call
to pass callbacks to them.
Hi @anuragvohraec I have followed the three steps you mentioned to use it, but Promise's then still won't be able to call it,I also noticed the method mentioned in this(https://github.com/bellard/quickjs/issues/140), but I don't know how to solve it
Hi All,
I was implementing WritableStream specification (Web api).As per it I need to create a promise and and then run certain code once its fullfilled.
I am able to create promise using the
JS_NewPromiseCapability
, but how do I set functions to run on its fullfillment or rejection,. basicaly pass functions to itsthen
andcatch
part ? All this has to be done at C side.