Files
opencloud/vendor/github.com/gookit/goutil/syncs/chan.go
T
PC Kitty d97217f22c Update github.com/gookit/goutil to v0.7.4 for FreeBSD compatibility
The goutil that OpenCloud currently uses is one version from the release that adds FreeBSD support, this now compiles successfully on FreeBSD.
2026-04-28 18:03:17 +02:00

23 lines
486 B
Go

package syncs
import "fmt"
// Go is a basic promise implementation: it wraps calls a function in a goroutine
// and returns a channel which will later return the function's return value.
//
// if panic happen, it will be recovered and return as error
func Go(f func() error) error {
ch := make(chan error)
go func() {
// add recovery handle
defer func() {
if r := recover(); r != nil {
ch <- fmt.Errorf("panic recover: %v", r)
}
}()
ch <- f()
}()
return <-ch
}