source: code/trunk/vendor/nhooyr.io/websocket/internal/xsync/go.go@ 822

Last change on this file since 822 was 822, checked in by yakumo.izuru, 22 months ago

Prefer immortal.run over runit and rc.d, use vendored modules
for convenience.

Signed-off-by: Izuru Yakumo <yakumo.izuru@…>

File size: 384 bytes
Line 
1package xsync
2
3import (
4 "fmt"
5)
6
7// Go allows running a function in another goroutine
8// and waiting for its error.
9func 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}
Note: See TracBrowser for help on using the repository browser.