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

Merge pull request #34929 from stevvooe/remove-promise-package

pkg/package: remove promise package
This commit is contained in:
Yong Tang 2017-09-22 11:52:23 -07:00 committed by GitHub
commit c982ee805d
5 changed files with 103 additions and 124 deletions

View file

@ -7,7 +7,6 @@ import (
"golang.org/x/net/context"
"github.com/docker/docker/pkg/pools"
"github.com/docker/docker/pkg/promise"
"github.com/docker/docker/pkg/term"
"github.com/sirupsen/logrus"
)
@ -58,7 +57,7 @@ func (c *Config) AttachStreams(cfg *AttachConfig) {
}
// CopyStreams starts goroutines to copy data in and out to/from the container
func (c *Config) CopyStreams(ctx context.Context, cfg *AttachConfig) chan error {
func (c *Config) CopyStreams(ctx context.Context, cfg *AttachConfig) <-chan error {
var (
wg sync.WaitGroup
errors = make(chan error, 3)
@ -137,7 +136,11 @@ func (c *Config) CopyStreams(ctx context.Context, cfg *AttachConfig) chan error
go attachStream("stdout", cfg.Stdout, cfg.CStdout)
go attachStream("stderr", cfg.Stderr, cfg.CStderr)
return promise.Go(func() error {
errs := make(chan error, 1)
go func() {
defer close(errs)
errs <- func() error {
done := make(chan struct{})
go func() {
wg.Wait()
@ -165,7 +168,10 @@ func (c *Config) CopyStreams(ctx context.Context, cfg *AttachConfig) chan error
}
}
return nil
})
}()
}()
return errs
}
func copyEscapable(dst io.Writer, src io.ReadCloser, keys []byte) (written int64, err error) {

View file

@ -20,7 +20,6 @@ import (
"github.com/docker/docker/pkg/idtools"
"github.com/docker/docker/pkg/ioutils"
"github.com/docker/docker/pkg/pools"
"github.com/docker/docker/pkg/promise"
"github.com/docker/docker/pkg/system"
"github.com/sirupsen/logrus"
)
@ -1095,7 +1094,12 @@ func (archiver *Archiver) CopyFileWithTar(src, dst string) (err error) {
}
r, w := io.Pipe()
errC := promise.Go(func() error {
errC := make(chan error, 1)
go func() {
defer close(errC)
errC <- func() error {
defer w.Close()
srcF, err := os.Open(src)
@ -1124,7 +1128,8 @@ func (archiver *Archiver) CopyFileWithTar(src, dst string) (err error) {
return err
}
return nil
})
}()
}()
defer func() {
if er := <-errC; err == nil && er != nil {
err = er

View file

@ -9,7 +9,6 @@ import (
"github.com/docker/docker/pkg/archive"
"github.com/docker/docker/pkg/idtools"
"github.com/docker/docker/pkg/promise"
"github.com/docker/docker/pkg/system"
"github.com/sirupsen/logrus"
)
@ -122,7 +121,11 @@ func (archiver *Archiver) CopyFileWithTar(src, dst string) (err error) {
}
r, w := io.Pipe()
errC := promise.Go(func() error {
errC := make(chan error, 1)
go func() {
defer close(errC)
errC <- func() error {
defer w.Close()
srcF, err := srcDriver.Open(src)
@ -155,7 +158,8 @@ func (archiver *Archiver) CopyFileWithTar(src, dst string) (err error) {
return err
}
return nil
})
}()
}()
defer func() {
if er := <-errC; err == nil && er != nil {
err = er

View file

@ -1,11 +0,0 @@
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
}

View file

@ -1,25 +0,0 @@
package promise
import (
"errors"
"testing"
"github.com/stretchr/testify/require"
)
func TestGo(t *testing.T) {
errCh := Go(functionWithError)
er := <-errCh
require.EqualValues(t, "Error Occurred", er.Error())
noErrCh := Go(functionWithNoError)
er = <-noErrCh
require.Nil(t, er)
}
func functionWithError() (err error) {
return errors.New("Error Occurred")
}
func functionWithNoError() (err error) {
return nil
}