Concurrency Reference¶
kostroutine¶
kostroutine fn(args...)schedules a function on runtime worker threads.waitAll()blocks until all scheduled routines finish.time.after(ms)returns a channel that receives once after timeout.
Channels¶
Create channels:
chan()for unbounded channelschan(n)for buffered channels (nmust be> 0)
Channel operations:
send(ch, value)recv(ch)close(ch)trySend(ch, value)returnsbooltryRecv(ch, fallback)returns received value or fallback
select¶
Supported case forms:
case recv(ch) as v:case send(ch, v):case timeout(ms):default:
Current behavior:
deterministic selection (first ready case in source order)
timeout(ms)requires non-negativeintmilliseconds
Common pattern¶
Use timeout channel from time.after:
import (
"time"
)
done = time.after(500)
select:
case recv(done):
print("timeout reached")