File: waiting_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 (39 lines) | stat: -rw-r--r-- 875 bytes parent folder | download
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
package tasklog

import (
	"fmt"
	"time"
)

// WaitingTask represents a task for which the total number of items to do work
// is on is unknown.
type WaitingTask struct {
	// ch is used to transmit task updates.
	ch chan *Update
}

// NewWaitingTask returns a new *WaitingTask.
func NewWaitingTask(msg string) *WaitingTask {
	ch := make(chan *Update, 1)
	ch <- &Update{
		S:  fmt.Sprintf("%s: ...", msg),
		At: time.Now(),
	}

	return &WaitingTask{ch: ch}
}

// Complete marks the task as completed.
func (w *WaitingTask) Complete() {
	close(w.ch)
}

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

// Throttled implements Task.Throttled and returns true, indicating that this
// task is Throttled.
func (w *WaitingTask) Throttled() bool { return true }