Browse code

Moved Go() to the main package... And got rid of the useless docker/future package

Solomon Hykes authored on 2013/03/21 17:13:55
Showing 4 changed files
... ...
@@ -6,7 +6,6 @@ import (
6 6
 	"errors"
7 7
 	"fmt"
8 8
 	"github.com/dotcloud/docker/auth"
9
-	"github.com/dotcloud/docker/future"
10 9
 	"github.com/dotcloud/docker/rcli"
11 10
 	"io"
12 11
 	"math/rand"
... ...
@@ -749,7 +748,7 @@ func (srv *Server) CmdRun(stdin io.ReadCloser, stdout io.Writer, args ...string)
749 749
 			return err
750 750
 		}
751 751
 		if *fl_attach {
752
-			future.Go(func() error {
752
+			Go(func() error {
753 753
 				_, err := io.Copy(cmd_stdin, stdin)
754 754
 				cmd_stdin.Close()
755 755
 				return err
... ...
@@ -769,11 +768,11 @@ func (srv *Server) CmdRun(stdin io.ReadCloser, stdout io.Writer, args ...string)
769 769
 		if err := container.Start(); err != nil {
770 770
 			return err
771 771
 		}
772
-		sending_stdout := future.Go(func() error {
772
+		sending_stdout := Go(func() error {
773 773
 			_, err := io.Copy(stdout, cmd_stdout)
774 774
 			return err
775 775
 		})
776
-		sending_stderr := future.Go(func() error {
776
+		sending_stderr := Go(func() error {
777 777
 			_, err := io.Copy(stdout, cmd_stderr)
778 778
 			return err
779 779
 		})
... ...
@@ -3,7 +3,6 @@ package main
3 3
 import (
4 4
 	"flag"
5 5
 	"github.com/dotcloud/docker"
6
-	"github.com/dotcloud/docker/future"
7 6
 	"github.com/dotcloud/docker/rcli"
8 7
 	"github.com/dotcloud/docker/term"
9 8
 	"io"
... ...
@@ -57,11 +56,11 @@ func runCommand(args []string) error {
57 57
 	// closing the connection.
58 58
 	// See http://code.google.com/p/go/issues/detail?id=3345
59 59
 	if conn, err := rcli.Call("tcp", "127.0.0.1:4242", args...); err == nil {
60
-		receive_stdout := future.Go(func() error {
60
+		receive_stdout := docker.Go(func() error {
61 61
 			_, err := io.Copy(os.Stdout, conn)
62 62
 			return err
63 63
 		})
64
-		send_stdin := future.Go(func() error {
64
+		send_stdin := docker.Go(func() error {
65 65
 			_, err := io.Copy(conn, os.Stdin)
66 66
 			if err := conn.CloseWrite(); err != nil {
67 67
 				log.Printf("Couldn't send EOF: " + err.Error())
68 68
deleted file mode 100644
... ...
@@ -1,11 +0,0 @@
1
-package future
2
-
3
-import ()
4
-
5
-func Go(f func() error) chan error {
6
-	ch := make(chan error)
7
-	go func() {
8
-		ch <- f()
9
-	}()
10
-	return ch
11
-}
... ...
@@ -14,6 +14,16 @@ import (
14 14
 	"time"
15 15
 )
16 16
 
17
+// Go is a basic promise implementation: it wraps calls a function in a goroutine,
18
+// and returns a channel which will later return the function's return value.
19
+func Go(f func() error) chan error {
20
+	ch := make(chan error)
21
+	go func() {
22
+		ch <- f()
23
+	}()
24
+	return ch
25
+}
26
+
17 27
 // Request a given URL and return an io.Reader
18 28
 func Download(url string, stderr io.Writer) (*http.Response, error) {
19 29
 	var resp *http.Response