Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could not remove jobs properly #35

Open
vigneshr6 opened this issue Mar 20, 2017 · 0 comments
Open

Could not remove jobs properly #35

vigneshr6 opened this issue Mar 20, 2017 · 0 comments

Comments

@vigneshr6
Copy link

vigneshr6 commented Mar 20, 2017

I have the below code

package main

import (
	"fmt"
	"time"

	"github.com/jasonlvhit/gocron"
)

func main() {
	funmap := make(map[string]func())
	for i := 1; i < 6; i++ {
		funmap[fmt.Sprintf("func%d", i)] = getJob(i)
	}
	gs := gocron.NewScheduler()
	gs.Every(5).Seconds().Do(funmap["func1"])
	gs.Every(5).Seconds().Do(funmap["func2"])
	gs.Every(5).Seconds().Do(funmap["func3"])
	gs.Every(5).Seconds().Do(funmap["func4"])
	gs.Every(5).Seconds().Do(funmap["func5"])
	fmt.Println(gs.Len())
	gs.Start()
	time.Sleep(time.Second * 10)
	fmt.Println("*************************")
	gs.Remove(funmap["func3"])
	gs.Remove(funmap["func5"])
	time.Sleep(time.Second * 10)
	gs.Clear()
}
func getJob(i int) func() {
	return func() {
		fmt.Println("This is func:", i)
	}
}

I want to remove jobs with their names.but It deletes first two entries.
How to solve this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant