Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions taskqueue/queuer.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,12 @@ func New(registerCallback func() func(func() error)) *TaskQueue {
// this is to work around the fact that RegistrerCallback doesn't know about Task
// related to https://github.com/golang/go/issues/8082
internal := func() func(Task) {
f := registerCallback()
enqueueCallback := registerCallback()
return func(t Task) {
f(t)
enqueueCallback(t)
}
}
tq := &TaskQueue{
callback: internal(),
registerCallback: internal,
}
return tq
Expand All @@ -44,15 +43,17 @@ func (tq *TaskQueue) Close() {
if tq.closed {
return
}
tq.closed = true
if tq.callback == nil {
tq.callback = tq.registerCallback()
}
if tq.callback == nil { // already something queued
tq.queue = append(tq.queue, func() error {
tq.Close()
return nil
})
return
}

tq.closed = true
tq.callback(func() error { return nil })
}

Expand All @@ -64,6 +65,9 @@ func (tq *TaskQueue) Queue(t Task) {
if tq.closed {
return
}
if tq.callback == nil {
tq.callback = tq.registerCallback()
}
if tq.callback == nil { // already something queued
tq.queue = append(tq.queue, t)
return
Expand Down
Loading