Debian Codegraph @

tasklog/task.go

raw symbols SCIP
1 package tasklog
2
3 import "time"
4
5 // Task is an interface which encapsulates an activity which can be logged.
6 type Task interface {
7 // Updates returns a channel which is written to with the current state
8 // of the Task when an update is present. It is closed when the task is
9 // complete.
10 Updates() <-chan *Update
11
12 // Throttled returns whether or not updates from this task should be
13 // limited when being printed to a sink via *log.Logger.
14 //
15 // It is expected to return the same value for a given Task instance.
16 Throttled() bool
17 }
18
19 // Update is a single message sent (S) from a Task at a given time (At).
20 type Update struct {
21 // S is the message sent in this update.
22 S string
23 // At is the time that this update was sent.
24 At time.Time
25
26 // Force determines if this update should not be throttled.
27 Force bool
28 }
29
30 // Throttled determines whether this update should be throttled, based on the
31 // given earliest time of the next update. The caller should determine how often
32 // updates should be throttled. An Update with Force=true is never throttled.
33 func (u *Update) Throttled(next time.Time) bool {
34 return !(u.Force || u.At.After(next))
35 }