Git Product home page Git Product logo

timing's Issues

task内 panic时 会恐慌,报错:使用了关闭的channel

复现代码:

task := &timing2.Task{
Uuid: "uuid",
Job: timing2.GetJob(func() {
panic("err")
}),
RunTime: time.Now().Unix() + 90,
}

异常代码处:
job.go func (j *taskJob) run()

原因是 defer的顺序是 先进后出,原代码会先触发 j.done <- true 然后进行了 finish的逻辑,代码应改为:

defer func() {
	if !isPanic {
		j.done <- true
	}
}()

defer func() {
	if x := recover(); x != nil {
		err := errors.Errorf("job error with panic:%v", x)
		j.err <- err
		isPanic = true
		return
	}
}()

TaskScheduler.run

你好, 在TaskScheduler.run 方法中,for循环存在的意义是什么?最后加了break,可见for循环只执行了一次

自定义任务,如何传入带参函数

起因

今天更新了一下包,发现你的包改动很大,导致之前写的代码无法编译通过。

还有就是之前你的包,似乎有点bug,就是我指定RunTime,Spacing,EndTime
发现并没有按照Spacing间隔执行,往往是只执行一次就没了。
但是指定Number就没有这个问题。

问题

image

我需要传入一个s参数,如何避免上述写法?

有几处理应替换addTask方法变为AddTask方法

还是有些问题哦老哥

timer.go文件里面的addTask方法没有处理runtime

timer.go文件有几处理应替换addTask方法变为AddTask方法

func (scheduler *TaskScheduler) AddFuncSpaceNumber(spaceTime int64, number int, f func()) {
	task := getTaskWithFuncSpacingNumber(spaceTime, number, f)
	scheduler.AddTask(task)
}
//add spacing time job to list with endTime
func (scheduler *TaskScheduler) AddFuncSpace(spaceTime int64, endTime int64, f func()) {
	task := getTaskWithFuncSpacing(spaceTime, endTime, f)
	scheduler.AddTask(task)
}

//add func to list
func (scheduler *TaskScheduler) AddFunc(unixTime int64, f func()) {
	task := getTaskWithFunc(unixTime, f)
	scheduler.AddTask(task)
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.