sciter-sdk / go-sciter

Golang bindings of Sciter: the Embeddable HTML/CSS/script engine for modern UI development
https://sciter.com
2.57k stars 268 forks source link

What is the solution asynchronous calling go functions in tiscript finally? #254

Closed jqqjj closed 3 years ago

jqqjj commented 3 years ago

My codes below:

Codes in tiscript side:

event click $(#btn){
        asyncSleep()
    };

    async function asyncSleep() {
        var p = promise();
        debug log("a")
        view.sleep(p)
        var rs = await p;
        debug log("b")
    }

Codes in go side:

func sleep(args ...*sciter.Value) *sciter.Value {
    p := args[0]

    log.Println("here")
    go waitHere(p.Clone())
    return sciter.NullValue()
}

func waitHere(p *sciter.Value) {
    time.Sleep(time.Second * 5)
    v, err := p.Invoke(sciter.NullValue(), "[sleep]", sciter.NewValue("OK"), sciter.NewValue())
    if err != nil {
        log.Println("err:", err)
    } else {
        log.Println(v)
    }
}

This codes will get error on tiscript:

promise failure: Error: Wrong type - undefined

How to return the right type in go codes?

jqqjj commented 3 years ago

I've seen AllenDang's codes here: #153 , But codes not work on my machine.

Could anyone show example codes?

Thanks.