mirror of
https://github.com/taigrr/wasm-experiments
synced 2025-01-18 04:03:21 -08:00
Try to call Fetch with a callback
This commit is contained in:
parent
0bc494b8b2
commit
70424ed5a8
@ -1,10 +1,14 @@
|
|||||||
|
// +build js,wasm
|
||||||
|
|
||||||
package fetch
|
package fetch
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"runtime/js"
|
"syscall/js"
|
||||||
|
"syscall/js/callback"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Method int
|
type Method int
|
||||||
@ -61,6 +65,11 @@ func Fetch(req Request) (Response, error) {
|
|||||||
}
|
}
|
||||||
init.Set("headers", headers)
|
init.Set("headers", headers)
|
||||||
|
|
||||||
|
cb := callback.New(func(args []js.Value) {
|
||||||
|
fmt.Println(args)
|
||||||
|
})
|
||||||
|
|
||||||
promise := js.Global.Call("fetch", req.URL.String(), init)
|
promise := js.Global.Call("fetch", req.URL.String(), init)
|
||||||
|
promise.Call("then", cb)
|
||||||
return Response{}, nil
|
return Response{}, nil
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
// +build js,wasm
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
Loading…
x
Reference in New Issue
Block a user