1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

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

This commit is contained in:
Solomon Hykes 2013-03-21 01:13:55 -07:00
parent deb603aaf4
commit 623e91e2e3
4 changed files with 15 additions and 18 deletions

View file

@ -6,7 +6,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"github.com/dotcloud/docker/auth" "github.com/dotcloud/docker/auth"
"github.com/dotcloud/docker/future"
"github.com/dotcloud/docker/rcli" "github.com/dotcloud/docker/rcli"
"io" "io"
"math/rand" "math/rand"
@ -749,7 +748,7 @@ func (srv *Server) CmdRun(stdin io.ReadCloser, stdout io.Writer, args ...string)
return err return err
} }
if *fl_attach { if *fl_attach {
future.Go(func() error { Go(func() error {
_, err := io.Copy(cmd_stdin, stdin) _, err := io.Copy(cmd_stdin, stdin)
cmd_stdin.Close() cmd_stdin.Close()
return err return err
@ -769,11 +768,11 @@ func (srv *Server) CmdRun(stdin io.ReadCloser, stdout io.Writer, args ...string)
if err := container.Start(); err != nil { if err := container.Start(); err != nil {
return err return err
} }
sending_stdout := future.Go(func() error { sending_stdout := Go(func() error {
_, err := io.Copy(stdout, cmd_stdout) _, err := io.Copy(stdout, cmd_stdout)
return err return err
}) })
sending_stderr := future.Go(func() error { sending_stderr := Go(func() error {
_, err := io.Copy(stdout, cmd_stderr) _, err := io.Copy(stdout, cmd_stderr)
return err return err
}) })

View file

@ -3,7 +3,6 @@ package main
import ( import (
"flag" "flag"
"github.com/dotcloud/docker" "github.com/dotcloud/docker"
"github.com/dotcloud/docker/future"
"github.com/dotcloud/docker/rcli" "github.com/dotcloud/docker/rcli"
"github.com/dotcloud/docker/term" "github.com/dotcloud/docker/term"
"io" "io"
@ -57,11 +56,11 @@ func runCommand(args []string) error {
// closing the connection. // closing the connection.
// See http://code.google.com/p/go/issues/detail?id=3345 // 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 { 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) _, err := io.Copy(os.Stdout, conn)
return err return err
}) })
send_stdin := future.Go(func() error { send_stdin := docker.Go(func() error {
_, err := io.Copy(conn, os.Stdin) _, err := io.Copy(conn, os.Stdin)
if err := conn.CloseWrite(); err != nil { if err := conn.CloseWrite(); err != nil {
log.Printf("Couldn't send EOF: " + err.Error()) log.Printf("Couldn't send EOF: " + err.Error())

View file

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

View file

@ -14,6 +14,16 @@ import (
"time" "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 // Request a given URL and return an io.Reader
func Download(url string, stderr io.Writer) (*http.Response, error) { func Download(url string, stderr io.Writer) (*http.Response, error) {
var resp *http.Response var resp *http.Response