File: list_task.go

package info (click to toggle)
git-lfs 3.6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,808 kB
  • sloc: sh: 21,256; makefile: 507; ruby: 417
file content (51 lines) | stat: -rw-r--r-- 1,075 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package tasklog

import (
	"fmt"
	"time"
)

// ListTask is a Task implementation that logs all updates in a list where each
// entry is line-delimited.
//
// For example:
//
//	entry #1
//	entry #2
//	msg: ..., done.
type ListTask struct {
	msg string
	ch  chan *Update
}

// NewListTask instantiates a new *ListTask instance with the given message.
func NewListTask(msg string) *ListTask {
	return &ListTask{
		msg: msg,
		ch:  make(chan *Update, 1),
	}
}

// Entry logs a line-delimited task entry.
func (l *ListTask) Entry(update string) {
	l.ch <- &Update{
		S:  fmt.Sprintf("%s\n", update),
		At: time.Now(),
	}
}

func (l *ListTask) Complete() {
	l.ch <- &Update{
		S:  fmt.Sprintf("%s: ...", l.msg),
		At: time.Now(),
	}
	close(l.ch)
}

// Throttled implements the Task.Throttled function and ensures that all log
// updates are printed to the sink.
func (l *ListTask) Throttled() bool { return false }

// Updates implements the Task.Updates function and returns a channel of updates
// to log to the sink.
func (l *ListTask) Updates() <-chan *Update { return l.ch }