diff --git a/promise/promise.go b/promise/promise.go new file mode 100644 index 0000000..dd52b90 --- /dev/null +++ b/promise/promise.go @@ -0,0 +1,11 @@ +package promise + +// 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. +func Go(f func() error) chan error { + ch := make(chan error, 1) + go func() { + ch <- f() + }() + return ch +}