grtm is a tool to manage golang goroutines.use this can start or stop a long loop goroutine.
go get github.com/scottkiss/grtm
package main
import (
"fmt"
"github.com/scottkiss/grtm"
"time"
)
func normal() {
fmt.Println("i am normal goroutine")
}
func main() {
gm := grtm.NewGrManager()
gm.NewGoroutine("normal", normal)
fmt.Println("main function")
time.Sleep(time.Second * time.Duration(5))
}
~
package main
import (
"fmt"
"github.com/scottkiss/grtm"
"time"
)
func normal() {
fmt.Println("i am normal goroutine")
}
func funcWithParams(args ...interface{}) {
fmt.Println(args[0].([]interface{})[0].(string))
fmt.Println(args[0].([]interface{})[1].(string))
}
func main() {
gm := grtm.NewGrManager()
gm.NewGoroutine("normal", normal)
fmt.Println("main function")
gm.NewGoroutine("funcWithParams", funcWithParams, "hello", "world")
time.Sleep(time.Second * time.Duration(5))
}
package main
import (
"fmt"
"github.com/scottkiss/grtm"
"time"
)
func myfunc() {
fmt.Println("do something repeat by interval 4 seconds")
time.Sleep(time.Second * time.Duration(4))
}
func main() {
gm := grtm.NewGrManager()
gm.NewLoopGoroutine("myfunc", myfunc)
fmt.Println("main function")
time.Sleep(time.Second * time.Duration(40))
fmt.Println("stop myfunc goroutine")
gm.StopLoopGoroutine("myfunc")
time.Sleep(time.Second * time.Duration(80))
}
output
main function
no signal
do something repeat by interval 4 seconds
no signal
do something repeat by interval 4 seconds
no signal
do something repeat by interval 4 seconds
no signal
do something repeat by interval 4 seconds
no signal
do something repeat by interval 4 seconds
no signal
do something repeat by interval 4 seconds
no signal
do something repeat by interval 4 seconds
no signal
do something repeat by interval 4 seconds
no signal
do something repeat by interval 4 seconds
no signal
do something repeat by interval 4 seconds
stop myfunc goroutine
gid[5577006791947779410] quit