-
Notifications
You must be signed in to change notification settings - Fork 0
/
core.go
44 lines (30 loc) · 805 Bytes
/
core.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package wasm
import (
"fmt"
"syscall/js"
"github.com/whosonfirst/go-whosonfirst-placetypes"
)
func IsCoreFunc(spec *placetypes.WOFPlacetypeSpecification) js.Func {
return js.FuncOf(func(this js.Value, args []js.Value) interface{} {
str_pt := args[0].String()
handler := js.FuncOf(func(this js.Value, args []js.Value) interface{} {
resolve := args[0]
reject := args[1]
go func() {
pt, err := spec.GetPlacetypeByName(str_pt)
if err != nil {
reject.Invoke(fmt.Sprintf("Failed to retrieve placetype with name %s, %v", str_pt, err))
return
}
if !pt.IsCorePlacetype() {
reject.Invoke()
return
}
resolve.Invoke()
}()
return nil
})
promiseConstructor := js.Global().Get("Promise")
return promiseConstructor.New(handler)
})
}