github.com/mdaxf/iac@v0.0.0-20240519030858-58a061660378/vendor_skip/nhooyr.io/websocket/internal/xsync/go.go (about) 1 package xsync 2 3 import ( 4 "fmt" 5 ) 6 7 // Go allows running a function in another goroutine 8 // and waiting for its error. 9 func Go(fn func() error) <-chan error { 10 errs := make(chan error, 1) 11 go func() { 12 defer func() { 13 r := recover() 14 if r != nil { 15 select { 16 case errs <- fmt.Errorf("panic in go fn: %v", r): 17 default: 18 } 19 } 20 }() 21 errs <- fn() 22 }() 23 24 return errs 25 }