promise.go 285 B

1234567891011
  1. package promise
  2. // Go is a basic promise implementation: it wraps calls a function in a goroutine,
  3. // and returns a channel which will later return the function's return value.
  4. func Go(f func() error) chan error {
  5. ch := make(chan error, 1)
  6. go func() {
  7. ch <- f()
  8. }()
  9. return ch
  10. }