diff --git a/commands.go b/commands.go index d56f77aab2..6f7b12be41 100644 --- a/commands.go +++ b/commands.go @@ -6,7 +6,6 @@ import ( "errors" "fmt" "github.com/dotcloud/docker/auth" - "github.com/dotcloud/docker/future" "github.com/dotcloud/docker/rcli" "io" "math/rand" @@ -749,7 +748,7 @@ func (srv *Server) CmdRun(stdin io.ReadCloser, stdout io.Writer, args ...string) return err } if *fl_attach { - future.Go(func() error { + Go(func() error { _, err := io.Copy(cmd_stdin, stdin) cmd_stdin.Close() return err @@ -769,11 +768,11 @@ func (srv *Server) CmdRun(stdin io.ReadCloser, stdout io.Writer, args ...string) if err := container.Start(); err != nil { return err } - sending_stdout := future.Go(func() error { + sending_stdout := Go(func() error { _, err := io.Copy(stdout, cmd_stdout) return err }) - sending_stderr := future.Go(func() error { + sending_stderr := Go(func() error { _, err := io.Copy(stdout, cmd_stderr) return err }) diff --git a/docker/docker.go b/docker/docker.go index 79fe582e97..5fc70f064f 100644 --- a/docker/docker.go +++ b/docker/docker.go @@ -3,7 +3,6 @@ package main import ( "flag" "github.com/dotcloud/docker" - "github.com/dotcloud/docker/future" "github.com/dotcloud/docker/rcli" "github.com/dotcloud/docker/term" "io" @@ -57,11 +56,11 @@ func runCommand(args []string) error { // closing the connection. // See http://code.google.com/p/go/issues/detail?id=3345 if conn, err := rcli.Call("tcp", "127.0.0.1:4242", args...); err == nil { - receive_stdout := future.Go(func() error { + receive_stdout := docker.Go(func() error { _, err := io.Copy(os.Stdout, conn) return err }) - send_stdin := future.Go(func() error { + send_stdin := docker.Go(func() error { _, err := io.Copy(conn, os.Stdin) if err := conn.CloseWrite(); err != nil { log.Printf("Couldn't send EOF: " + err.Error()) diff --git a/future/future.go b/future/future.go deleted file mode 100644 index fa9d348fcc..0000000000 --- a/future/future.go +++ /dev/null @@ -1,11 +0,0 @@ -package future - -import () - -func Go(f func() error) chan error { - ch := make(chan error) - go func() { - ch <- f() - }() - return ch -} diff --git a/utils.go b/utils.go index e8fefafb2b..29f62f7534 100644 --- a/utils.go +++ b/utils.go @@ -14,6 +14,16 @@ import ( "time" ) +// 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) + go func() { + ch <- f() + }() + return ch +} + // Request a given URL and return an io.Reader func Download(url string, stderr io.Writer) (*http.Response, error) { var resp *http.Response