I try the code TinyGo on Wio Terminal to feel the operation of goroutine
It is not a preemptive time-share style thread.
So ... beware of long runnung operation.
Following is Simulation of Running Operation
primeFinder := func(
done <-chan interface{},
iStream <-chan int,
) <-chan interface{} {
pStream := make(chan interface{})
go func() {
defer close(pStream)
for iV := range iStream {
iV -= 1
prime := true
for d := iV - 1; d > 1; d-- {
if iV%d == 0 {
prime = false
break
}
}
if prime {
select {
case <-done:
return
case pStream <- iV:
}
}
}
}()
return pStream
}
PS. Use tinygo on wio terminal feel nicer than rust. :(
Comments