diff --git a/main_test.go b/main_test.go index f4f973f1..d1ef1964 100644 --- a/main_test.go +++ b/main_test.go @@ -164,7 +164,7 @@ func runPlatTests(options compileopts.Options, tests []string, t *testing.T) { t.Parallel() runTest("env.go", options, t, []string{"first", "second"}, []string{"ENV1=VALUE1", "ENV2=VALUE2"}) }) - if options.Target == "wasi" { + if options.Target == "wasi" || options.Target == "wasm" { t.Run("alias.go-scheduler-none", func(t *testing.T) { t.Parallel() options := compileopts.Options(options) diff --git a/src/runtime/runtime_wasm_js.go b/src/runtime/runtime_wasm_js.go index a5f2505d..60d8760d 100644 --- a/src/runtime/runtime_wasm_js.go +++ b/src/runtime/runtime_wasm_js.go @@ -29,34 +29,6 @@ func setEventHandler(fn func()) { handleEvent = fn } -//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 -} - func ticksToNanoseconds(ticks timeUnit) int64 { // The JavaScript API works in float64 milliseconds, so convert to // nanoseconds first before converting to a timeUnit (which is a float64), diff --git a/src/runtime/runtime_wasm_js_scheduler.go b/src/runtime/runtime_wasm_js_scheduler.go new file mode 100644 index 00000000..ab80cf1d --- /dev/null +++ b/src/runtime/runtime_wasm_js_scheduler.go @@ -0,0 +1,32 @@ +//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 +}