以为是win的bug, 结果再在ubuntu上重新试了下还是一样的错误
panic: trying to make exported function async: Multiple
用于编译goroutine 时报错
package main
func Fib(n int) int {
if n < 2 {
return n
}
return Fib(n-1) + Fib(n-2)
}
func FibMul(n int, c chan int) {
c <- Fib(n)
}
//go:export Multiple
func Multiple(size int) []int {
ans := make([]int, size)
c := make(chan int, size)
for i := 0; i < size; i++ {
go FibMul(i, c)
}
for i := 0; i < size; i++ {
ans[i] = <-c
}
return ans
}
func main() {
}
// set GOARCH=wasm
// set GOOS=js
// go build -o lib.wasm fib-list.go
// tinygo build -o fib-list.wasm -target=wasm fib-list.go
来源:oschina
链接:https://my.oschina.net/ahaoboy/blog/3211312