mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
These comments were added to enforce using the correct import path for
our packages ("github.com/docker/docker", not "github.com/moby/moby").
However, when working in go module mode (not GOPATH / vendor), they have
no effect, so their impact is limited.
Remove these imports in preparation of migrating our code to become an
actual go module.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
38 lines
540 B
Go
38 lines
540 B
Go
package queue
|
|
|
|
import "sync"
|
|
|
|
// Queue is the structure used for holding functions in a queue.
|
|
type Queue struct {
|
|
sync.Mutex
|
|
fns map[string]chan struct{}
|
|
}
|
|
|
|
// Append adds an item to a queue.
|
|
func (q *Queue) Append(id string, f func()) {
|
|
q.Lock()
|
|
defer q.Unlock()
|
|
|
|
if q.fns == nil {
|
|
q.fns = make(map[string]chan struct{})
|
|
}
|
|
|
|
done := make(chan struct{})
|
|
|
|
fn, ok := q.fns[id]
|
|
q.fns[id] = done
|
|
go func() {
|
|
if ok {
|
|
<-fn
|
|
}
|
|
f()
|
|
close(done)
|
|
|
|
q.Lock()
|
|
if q.fns[id] == done {
|
|
delete(q.fns, id)
|
|
}
|
|
q.Unlock()
|
|
}()
|
|
}
|