Jelajahi Sumber

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

Solomon Hykes 12 tahun lalu
induk
melakukan
623e91e2e3
4 mengubah file dengan 15 tambahan dan 18 penghapusan
  1. 3 4
      commands.go
  2. 2 3
      docker/docker.go
  3. 0 11
      future/future.go
  4. 10 0
      utils.go

+ 3 - 4
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
 		})

+ 2 - 3
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())

+ 0 - 11
future/future.go

@@ -1,11 +0,0 @@
-package future
-
-import ()
-
-func Go(f func() error) chan error {
-	ch := make(chan error)
-	go func() {
-		ch <- f()
-	}()
-	return ch
-}

+ 10 - 0
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