Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gagliardetto/eta
Estimate time to completion
https://github.com/gagliardetto/eta
Last synced: about 2 months ago
JSON representation
Estimate time to completion
- Host: GitHub
- URL: https://github.com/gagliardetto/eta
- Owner: gagliardetto
- Created: 2020-05-11T08:51:08.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-03-07T18:25:23.000Z (almost 4 years ago)
- Last Synced: 2024-10-12T01:31:09.468Z (3 months ago)
- Language: Go
- Homepage:
- Size: 3.91 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Install
```bash
go get -u github.com/gagliardetto/eta
```## Why I wrote it
I needed time estimates for when running tasks will be completed.
## Usage
```golang
package mainimport (
"fmt"
"time""github.com/gagliardetto/eta"
"github.com/hako/durafmt"
)func main() {
totalTasks := int64(60)
etac := eta.New(totalTasks)// Execute tasks:
go func() {
for {
func() {
// Mark one task done:
defer etac.Done(1)
err := runTask()
if err != nil {
panic(err)
}
}()
}
}()// Print stats:
for {
time.Sleep(time.Second)
averagedETA := etac.GetETA()
thisETA := durafmt.Parse(averagedETA.Round(time.Second)).String()percentDone := etac.GetFormattedPercentDone()
fmt.Println(thisETA, percentDone)
}
}
func runTask() error {
time.Sleep(time.Second * 2)
return nil
}```