tinygo/src/runtime/runtime_wasm_js_scheduler.go
Ayke van Laethem 51290e5842 wasm: support -scheduler=none
Previously, -scheduler=none wasn't possible for WASM targets:

    $ tinygo run -target=wasm -scheduler=none ./testdata/stdlib.go
    src/runtime/runtime_wasm_js.go:34:2: attempted to start a goroutine without a scheduler

With this commit, it works just fine:

    $ tinygo run -target=wasm -scheduler=none ./testdata/stdlib.go
    stdin:  /dev/stdin
    stdout: /dev/stdout
    stderr: /dev/stderr
    pseudorandom number: 1298498081
    strings.IndexByte: 2
    strings.Replace: An-example-string

Supporting `-scheduler=none` has some benefits:

  * it reduces file size a lot compared to having a scheduler
  * it allows JavaScript to call exported functions
2021-11-17 19:03:20 +01:00

32 строки
405 Б
Go

//go:build wasm && !wasi && !scheduler.none
// +build wasm,!wasi,!scheduler.none
package runtime
//export resume
func resume() {
go func() {
handleEvent()
}()
if wasmNested {
minSched()
return
}
wasmNested = true
scheduler()
wasmNested = false
}
//export go_scheduler
func go_scheduler() {
if wasmNested {
minSched()
return
}
wasmNested = true
scheduler()
wasmNested = false
}