Skip to content

Commit

Permalink
Added RunImmediate() method
Browse files Browse the repository at this point in the history
  • Loading branch information
papa-stiflera committed Feb 13, 2017
1 parent 1379d87 commit 3844612
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion gocron.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ func getFunctionName(fn interface{}) string {
}

// Specifies the jobFunc that should be called every time the job runs
//
func (j *Job) Do(jobFun interface{}, params ...interface{}) {
typ := reflect.TypeOf(jobFun)
if typ.Kind() != reflect.Func {
Expand All @@ -128,6 +127,22 @@ func (j *Job) Do(jobFun interface{}, params ...interface{}) {
j.Unlock()
}

func (j *Job) DoImmediate(jobFun interface{}, params ...interface{}) {
typ := reflect.TypeOf(jobFun)
if typ.Kind() != reflect.Func {
panic("only function can be schedule into the job queue.")
}

fname := getFunctionName(jobFun)
j.Lock()
j.funcs[fname] = jobFun
j.fparams[fname] = params
j.jobFunc = fname
j.Unlock()
//immediate run
j.run()
}

func (j *Job) at(t string) *Job {
hour := int((t[0]-'0')*10 + (t[1] - '0'))
min := int((t[3]-'0')*10 + (t[4] - '0'))
Expand Down

0 comments on commit 3844612

Please sign in to comment.