コード風プロンプト例5i Goのgoroutine:タイムアウト処理
Simulate Go goroutine timeout behavior. Use this to test how your code handles channel operations that exceed time limits.
/plugin marketplace add kokuyouwind/claude-plugins/plugin install code-like-prompt@kokuyouwind-plugins[--timeout=SEC]Emulate the following Go-style code internally (without using external tools or interpreter). Output only what fmt.Println() commands would output. Do not show any explanations, code, variables, or other messages.
package main
import (
"fmt"
"time"
)
func main() {
ch := make(chan string)
go func() {
time.Sleep(2 * time.Second)
ch <- "foo"
}()
timeout := 1
if timeout_arg != nil {
timeout = timeout_arg
}
select {
case msg := <-ch:
fmt.Println(msg)
case <-time.After(timeout * time.Second):
fmt.Println("bar")
}
fmt.Println("baz")
}