Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

timewheel on golang

NotificationsYou must be signed in to change notification settings

tttxdxd/timewheel

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

timewheel on golang

使用

timewheel:=NewTimeWheel()timewheel.Start()timewheel.SetTimeout(3000,func() {})id:=timewheel.SetInterval(3000,func() {})timewheel.Stop(id)

主要逻辑

  • 使用最小堆,取注册的离当前最近的定时任务
  • 若任务过期,立即执行,否则等待至规定的时间
  • 在等待过程中有其他任务注册时,将重新计算最近的定时任务

其他

  • 加入极简协程池 goroutine pool,减少阻塞的情况
  • 使用 map 记录被关闭的任务,当任务为最近的定时任务时,将被直接抛出

后续计划

  • 加入 WaitGroup,与主线程同步
  • 加入多个时间轮
  • 协程池将根据任务量,执行情况动态管理

Releases

No releases published

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp