wasm: don't block //go:wasmexport because of running goroutines

This fixes bug https://github.com/tinygo-org/tinygo/issues/4874.
This commit is contained in:
Ayke van Laethem
2025-04-28 10:47:39 +02:00
committed by Ron Evans
parent 0c2ab895b7
commit 612a38e363
8 changed files with 46 additions and 1 deletions
+6
View File
@@ -39,3 +39,9 @@ func reentrantCall(a, b int32) int32 {
println("reentrantCall result:", result)
return result
}
//go:wasmexport goroutineExit
func goroutineExit() {
// Dummy, not a real test (since we have no scheduler).
println("goroutineExit: exit")
}
+16 -1
View File
@@ -1,6 +1,9 @@
package main
import "time"
import (
"runtime"
"time"
)
func init() {
println("called init")
@@ -50,3 +53,15 @@ func reentrantCall(a, b int32) int32 {
println("reentrantCall result:", result)
return result
}
// Test for bug: https://github.com/tinygo-org/tinygo/issues/4874
//
//go:wasmexport goroutineExit
func goroutineExit() {
go func() {
time.Sleep(time.Second * 10)
println("goroutineExit: exiting goroutine")
}()
runtime.Gosched()
println("goroutineExit: exit")
}
+1
View File
@@ -15,6 +15,7 @@ function runTests() {
testCall('add', [6, 1], 7);
testCall('reentrantCall', [2, 3], 5);
testCall('reentrantCall', [1, 8], 9);
testCall('goroutineExit', [], undefined);
}
let go = new Go();
+1
View File
@@ -9,3 +9,4 @@ reentrantCall result: 5
reentrantCall: 1 8
called add: 1 8
reentrantCall result: 9
goroutineExit: exit