-
Notifications
You must be signed in to change notification settings - Fork 388
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
how to get a resolve value in a promise? #508
Comments
Export to promise func main() {
vm := goja.New()
_, err := vm.RunString(`
async function sum(a, b) {
return a+b;
}
`)
if err != nil {
panic(err)
}
add, ok := goja.AssertFunction(vm.Get("sum"))
if !ok {
panic("not a function")
}
value, _ := add(goja.Undefined(), vm.ToValue(40), vm.ToValue(2))
var result any
if p, ok := value.Export().(*goja.Promise); ok {
switch p.State() {
case goja.PromiseStateRejected:
panic(p.Result().String())
case goja.PromiseStateFulfilled:
result = p.Result().Export()
default:
panic("unexpected promise state pending")
}
}
fmt.Println(result)
} |
I would like to ask a question,the promise is async,so in goja in golang it is sync?If the execution is not completed when the results are obtained,it is true? |
It's async, you can also see Lines 592 to 611 in 28ee0ee
|
hey team, i have some confusions in these code
in this example, the sum Function return a [object, Promise], but i want to get a Resolved value, please tell me how do i?
The text was updated successfully, but these errors were encountered: