mirror of
https://github.com/nxshock/go-eta.git
synced 2025-07-01 00:13:40 +05:00
Add example
This commit is contained in:
parent
4004b0c918
commit
ffb165bcc4
1 changed files with 41 additions and 0 deletions
41
README.md
41
README.md
|
@ -1,3 +1,44 @@
|
|||
# go-eta
|
||||
|
||||
ETA calculator for Go.
|
||||
|
||||
## Example
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/nxshock/go-eta"
|
||||
)
|
||||
|
||||
func main() {
|
||||
stepsCount := 1000
|
||||
|
||||
eta := eta.New(time.Minute, stepsCount)
|
||||
|
||||
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"))
|
||||
}
|
||||
|
||||
}
|
||||
```
|
Loading…
Add table
Add a link
Reference in a new issue