Energy provides a concurrent energy system, useful for games and other applications.
Energy was heavily inspired by Heungsub Lee's energy module for Python.
e := energy.New(10,10,time.Second)
e.Use()
fmt.Println(e)
// <Energy 9/10>
e.UseEnergy(5)
fmt.Println(e)
// <Energy 4/10>
time.Sleep(time.Second)
fmt.Println(e)
// <Energy 5/10>
ok := e.UseEnergy(6)
if ok {
fmt.Println("Do something")
} else {
fmt.Println("Not enough energy")
}
// "Not enough energy"
go get -u -v github.com/liru/energy
- Add a WaitForUse() function that blocks until there is energy available.
- Write tests.
Use the issues
tab provided by Github at the top of this project's page.
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request :D