Skip to content

关于addOrRun方法的疑问 #43

@EddieChan1993

Description

@EddieChan1993
// addOrRun inserts the timer t into the current timing wheel, or run the
// timer's task if it has already expired.
func (tw *TimingWheel) addOrRun(t *Timer) {
	if !tw.add(t) {
		// Already expired

		// Like the standard time.AfterFunc (https://golang.org/pkg/time/#AfterFunc),
		// always execute the timer's task in its own goroutine.
		go t.task()
	}
}

如果大批量的时间过期,那此时不是会同时开启多个goroutine,会不会存在内存暴涨的情况。毕竟时间轮实用的场景是大量的时间任务管理的情况。其次就是为什么不考虑在此处加入协程池

其次,我想要在调用ScheduleFunc的过程中,限制任务的执行次数比如执行10次,每次间隔1s就够。如果我采用stop停止当前循环任务,无法达到精准控制次数的目的。

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions