ETA calculator for Go
Go to file
2022-08-10 21:09:50 +05:00
.gitattributes Initial commit 2022-08-03 21:45:26 +05:00
.gitignore Initial commit 2022-08-03 21:45:26 +05:00
consts.go Make params public 2022-08-10 21:08:34 +05:00
eta.go Move cycle time calculation to separate functions 2022-08-10 21:09:42 +05:00
go.mod Upload code 2022-08-03 21:50:02 +05:00
LICENSE Initial commit 2022-08-03 21:45:26 +05:00
README.md Update example 2022-08-10 21:09:50 +05:00

go-eta

ETA calculator for Go.

Example

package main

import (
	"fmt"
	"math/rand"
	"os"
	"time"

	"github.com/nxshock/go-eta"
)

func main() {
	stepsCount := 1000

	eta := eta.New(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"))
	}
}