
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
32 строки
405 Б
Go
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
|
|
}
|