From 205625473f1d4db3693642ea263358adb3c51d0d Mon Sep 17 00:00:00 2001 From: Brian Goff Date: Fri, 13 Oct 2017 12:37:23 -0400 Subject: [PATCH] Close wait chan after sending status This allows the caller to receive multiple times without blocking after the first call. This can be useful in cases like this: ```go ch, _ := task.Wait(ctx) defer func() { <-ch } // don't return until task is done task.Start(ctx) if err := doSomething(task); err != nil { return err } status := <- ch // do stuff with status ``` Since this channel is created in the `Wait()` calls and never accessible outside, this should be safe. Signed-off-by: Brian Goff --- process.go | 1 + task.go | 1 + 2 files changed, 2 insertions(+) diff --git a/process.go b/process.go index ef11a63b0..e51367aaa 100644 --- a/process.go +++ b/process.go @@ -120,6 +120,7 @@ func (p *process) Kill(ctx context.Context, s syscall.Signal, opts ...KillOpts) func (p *process) Wait(ctx context.Context) (<-chan ExitStatus, error) { c := make(chan ExitStatus, 1) go func() { + defer close(c) r, err := p.task.client.TaskService().Wait(ctx, &tasks.WaitRequest{ ContainerID: p.task.id, ExecID: p.id, diff --git a/task.go b/task.go index bf830d2cf..86a00cc48 100644 --- a/task.go +++ b/task.go @@ -215,6 +215,7 @@ func (t *task) Status(ctx context.Context) (Status, error) { func (t *task) Wait(ctx context.Context) (<-chan ExitStatus, error) { c := make(chan ExitStatus, 1) go func() { + defer close(c) r, err := t.client.TaskService().Wait(ctx, &tasks.WaitRequest{ ContainerID: t.id, })