From 32cc6ab501fc738f374845c78a7d37a78e16f29a Mon Sep 17 00:00:00 2001 From: Rafe Colton Date: Mon, 29 Sep 2014 23:16:27 -0700 Subject: [PATCH] Move Go() promise-like func from utils to pkg/promise This is the first of two steps to break the archive package's dependence on utils so that archive may be moved into pkg. Also, the `Go()` function is small, concise, and not specific to the docker internals, so it is a good candidate for pkg. Signed-off-by: Rafe Colton --- promise/promise.go | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 promise/promise.go 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 +}