From 70424ed5a8d08e5d1cb82e4f766e326679303694 Mon Sep 17 00:00:00 2001 From: Johan Brandhorst Date: Sat, 12 May 2018 15:07:32 +0100 Subject: [PATCH] Try to call Fetch with a callback --- fetch/fetch/fetch.go | 11 ++++++++++- fetch/main.go | 2 ++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/fetch/fetch/fetch.go b/fetch/fetch/fetch.go index c9c9868..b1a9a66 100644 --- a/fetch/fetch/fetch.go +++ b/fetch/fetch/fetch.go @@ -1,10 +1,14 @@ +// +build js,wasm + package fetch import ( + "fmt" "io" "net/http" "net/url" - "runtime/js" + "syscall/js" + "syscall/js/callback" ) type Method int @@ -61,6 +65,11 @@ func Fetch(req Request) (Response, error) { } init.Set("headers", headers) + cb := callback.New(func(args []js.Value) { + fmt.Println(args) + }) + promise := js.Global.Call("fetch", req.URL.String(), init) + promise.Call("then", cb) return Response{}, nil } diff --git a/fetch/main.go b/fetch/main.go index fa89c9b..9459111 100644 --- a/fetch/main.go +++ b/fetch/main.go @@ -1,3 +1,5 @@ +// +build js,wasm + package main import (