Skip to content

Commit 3d872ab

Browse files
committed
tasklog/log.go: simplify consume() method
The *Logger.consume() method in the "tasklog" package was first introduced in commit e90d54d of PR git-lfs#2329, and since that time has included logic to manage an internal "pending" list of tasks; however, that logic is never exercised because tasks are only appended to the "pending" array when the "next" variable is non-nil, but that variable is initialized as nil and can only be set to another value if the "pending" array is non-empty. As a result, we can remove both variables and the related logic and simplify the consume() method as a result.
1 parent 1cb3dc3 commit 3d872ab

File tree

1 file changed

+10
-41
lines changed

1 file changed

+10
-41
lines changed

tasklog/log.go

Lines changed: 10 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -189,50 +189,19 @@ func (l *Logger) consume() {
189189

190190
defer close(l.tasks)
191191

192-
pending := make([]Task, 0)
193-
194192
for {
195-
// If there is a pending task, "peek" it off of the set of
196-
// pending tasks.
197-
var next Task
198-
if len(pending) > 0 {
199-
next = pending[0]
193+
// Wait for either a) l.queue to close, or b) a new task
194+
// to be submitted.
195+
task, ok := <-l.queue
196+
if !ok {
197+
// If the queue is closed, no more new tasks may
198+
// be added.
199+
return
200200
}
201201

202-
if next == nil {
203-
// If there was no pending task, wait for either a)
204-
// l.queue to close, or b) a new task to be submitted.
205-
task, ok := <-l.queue
206-
if !ok {
207-
// If the queue is closed, no more new tasks may
208-
// be added.
209-
return
210-
}
211-
212-
// Otherwise, add a new task to the set of tasks to
213-
// process immediately, since there is no current
214-
// buffer.
215-
l.tasks <- task
216-
} else {
217-
// If there is a pending task, wait for either a) a
218-
// write to process the task to become non-blocking, or
219-
// b) a new task to enter the queue.
220-
select {
221-
case task, ok := <-l.queue:
222-
if !ok {
223-
// If the queue is closed, no more tasks
224-
// may be added.
225-
return
226-
}
227-
// Otherwise, add the next task to the set of
228-
// pending, active tasks.
229-
pending = append(pending, task)
230-
case l.tasks <- next:
231-
// Or "pop" the peeked task off of the pending
232-
// set.
233-
pending = pending[1:]
234-
}
235-
}
202+
// Otherwise, add a new task to the set of tasks to
203+
// process immediately.
204+
l.tasks <- task
236205
}
237206
}
238207

0 commit comments

Comments
 (0)