You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
384 B
25 lines
384 B
package xsync |
|
|
|
import ( |
|
"fmt" |
|
) |
|
|
|
// Go allows running a function in another goroutine |
|
// and waiting for its error. |
|
func Go(fn func() error) <-chan error { |
|
errs := make(chan error, 1) |
|
go func() { |
|
defer func() { |
|
r := recover() |
|
if r != nil { |
|
select { |
|
case errs <- fmt.Errorf("panic in go fn: %v", r): |
|
default: |
|
} |
|
} |
|
}() |
|
errs <- fn() |
|
}() |
|
|
|
return errs |
|
}
|
|
|