From 5993b3e846b42012b457cb646404a5ea84d0bb84 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Fri, 6 May 2016 12:45:03 +0100 Subject: [PATCH] Refactor: extract function to look up waiting channel for container --- proxy/proxy.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/proxy/proxy.go b/proxy/proxy.go index 74eccfdf..6291c091 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -438,18 +438,20 @@ func (proxy *Proxy) waitForStart(r *http.Request) error { return nil } -// If some other operation is waiting for a container to start, join in the wait -func (proxy *Proxy) waitForStartByIdent(ident string) error { - var ch chan error +func (proxy *Proxy) waitChan(ident string) chan error { proxy.Lock() + defer proxy.Unlock() for _, wait := range proxy.waiters { if ident == wait.ident && !wait.done { - ch = wait.ch - break + return wait.ch } } - proxy.Unlock() - if ch != nil { + return nil +} + +// If some other operation is waiting for a container to start, join in the wait +func (proxy *Proxy) waitForStartByIdent(ident string) error { + if ch := proxy.waitChan(ident); ch != nil { Log.Debugf("Wait for start of container %s", ident) return <-ch }