You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In Go you have to check if the result value from V8 is a promise; if it is, you check its state. As long as it's still in the unresolved state, you call the context's PerformMicrotaskCheckpoint method to run a bit longer, then recheck the promise state.
funcresolvePromise(val*v8.Value, errerror) (*v8.Value, error) {
iferr!=nil||!val.IsPromise() {
returnval, err
}
for {
switchp, _:=val.AsPromise(); p.State() {
casev8.Fulfilled:
returnp.Result(), nilcasev8.Rejected:
returnnil, errors.New(p.Result().DetailString())
casev8.Pending:
r.ctx.PerformMicrotaskCheckpoint() // run VM to make progress on the promise// go round the loop again...default:
returnnil, fmt.Errorf("illegal v8.Promise state %d", p) // unreachable
}
}
}
Hey,
assuming this code:
how to properly handle a promise and get a value from
result
?Ofc. above example without async/await works flawlessly.
The text was updated successfully, but these errors were encountered: