store_wasm.mx raw
1 //go:build wasm
2 //:build wasm
3
4 package store
5
6 import (
7 "git.smesh.lol/smesh/web/common/jsbridge/callback"
8 "unsafe"
9 )
10
11 //:wasmimport bridge store_worker_on_message
12 func wasmWorkerOnMessage(cbID int32)
13
14 //:wasmimport bridge store_worker_post
15 func wasmWorkerPost(ptr *byte, length int32, cap int32)
16
17 //:wasmimport bridge store_worker_set_timeout
18 func wasmWorkerSetTimeout(ms int32, cbID int32) (n int32)
19
20 //:wasmimport bridge store_worker_clear_timeout
21 func wasmWorkerClearTimeout(handle int32)
22
23 //:wasmimport bridge store_worker_now_seconds
24 func wasmWorkerNowSeconds() (n int64)
25
26 func WorkerOnMessage(fn func(msg string)) {
27 wasmWorkerOnMessage(callback.RegisterS(fn))
28 }
29
30 func WorkerPost(msg string) {
31 wasmWorkerPost(unsafe.StringData(msg), int32(len(msg)), int32(len(msg)))
32 }
33
34 func WorkerSetTimeout(ms int32, fn func()) (n int32) {
35 return wasmWorkerSetTimeout(ms, callback.Register0Once(fn))
36 }
37
38 func WorkerClearTimeout(handle int32) { wasmWorkerClearTimeout(handle) }
39 func WorkerNowSeconds() (n int64) { return wasmWorkerNowSeconds() }
40