Documentation ¶
Overview ¶
Package multistatus will print a continuously updating block of text to the stdout to show the current status of a set of concurrent goroutines.
Usage:
import ( "context" "fmt" "math/rand" "time" ms "github.com/zikes/multistatus" ) func main() { // Create a new WorkerSet ws := ms.New() // Populate the WorkerSet with Workers for i := 0; i < 10; i++ { w := ws.Add(fmt.Sprintf("Task #%d", i)) go func(w *ms.Worker) { // Sleep for 0-8 seconds, then tell the Worker it failed or completed time.Sleep(time.Millisecond * time.Duration(rand.Intn(8000))) if rand.Intn(5) == 1 { w.Fail() } else { w.Done() } }(w) } // Print the WorkerSet's status until all Workers have completed ws.Print(context.Background()) }
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Worker ¶
type Worker struct { State WorkerState Name string // contains filtered or unexported fields }
Worker is used to track the status of a worker task
type WorkerSet ¶
type WorkerSet struct { Workers []*Worker // contains filtered or unexported fields }
A WorkerSet is a collection of Workers
func (*WorkerSet) Add ¶
Add creates and returns a new Worker, and increments the WorkerSet's sync.WaitGroup
func (*WorkerSet) Print ¶
Print initiates the WorkerSet's sync.WaitGroup.Wait() and continuously prints the status of all the Workers in its collection, cancelable via context cancelation.
If the stdout is determined to not be a terminal then it will not print until the WaitGroup has finished, and its output will be free of terminal escapes.
type WorkerState ¶
type WorkerState int
WorkerState represent the current state of a Worker
const ( Completed WorkerState = iota Failed Pending )
Available Worker states