2017-11-22 22:07:24 +00:00
|
|
|
package tasklog
|
2017-06-14 21:55:50 +00:00
|
|
|
|
2017-08-09 21:45:18 +00:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"time"
|
|
|
|
)
|
2017-06-14 21:55:50 +00:00
|
|
|
|
|
|
|
// 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.
|
2017-08-09 21:45:18 +00:00
|
|
|
ch chan *Update
|
2017-06-14 21:55:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewWaitingTask returns a new *WaitingTask.
|
|
|
|
func NewWaitingTask(msg string) *WaitingTask {
|
2017-08-09 21:45:18 +00:00
|
|
|
ch := make(chan *Update, 1)
|
|
|
|
ch <- &Update{
|
|
|
|
S: fmt.Sprintf("%s: ...", msg),
|
|
|
|
At: time.Now(),
|
|
|
|
}
|
2017-06-14 21:55:50 +00:00
|
|
|
|
|
|
|
return &WaitingTask{ch: ch}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Complete marks the task as completed.
|
|
|
|
func (w *WaitingTask) Complete() {
|
|
|
|
close(w.ch)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Done implements Task.Done and returns a channel which is closed when
|
|
|
|
// Complete() is called.
|
2017-08-09 21:45:18 +00:00
|
|
|
func (w *WaitingTask) Updates() <-chan *Update {
|
2017-06-14 21:55:50 +00:00
|
|
|
return w.ch
|
|
|
|
}
|
2017-06-19 20:10:07 +00:00
|
|
|
|
2017-06-19 20:19:19 +00:00
|
|
|
// Throttled implements Task.Throttled and returns true, indicating that this
|
|
|
|
// task is Throttled.
|
|
|
|
func (w *WaitingTask) Throttled() bool { return true }
|