go-eta/README.md

43 lines
608 B
Markdown
Raw Permalink Normal View History

2022-08-03 21:45:26 +05:00
# go-eta
2022-08-03 21:50:02 +05:00
ETA calculator for Go.
2022-08-03 22:00:52 +05:00
## Example
```go
package main
import (
"fmt"
"math/rand"
"os"
"time"
"github.com/nxshock/go-eta"
)
func main() {
stepsCount := 1000
2022-08-10 21:09:50 +05:00
eta := eta.New(stepsCount)
2022-08-03 22:00:52 +05:00
processed := 0
// Emulate work
go func() {
for processed < stepsCount {
time.Sleep(time.Second)
r := rand.Intn(30)
processed += r
eta.Increment(r)
}
}()
// Print progress
for processed < stepsCount {
time.Sleep(time.Second) // Update progress every second
fmt.Fprintf(os.Stderr, "\rProcessed %d of %d, ETA: %s", processed, stepsCount, eta.Eta().Format("15:04:05"))
}
}
```