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

add Quick mode for gtimer #2488

Merged
merged 4 commits into from
Mar 20, 2023
Merged

add Quick mode for gtimer #2488

merged 4 commits into from
Mar 20, 2023

Conversation

hinego
Copy link
Contributor

@hinego hinego commented Mar 3, 2023

This commit adds a new Quick bool to the timer code, which can be used to set the timer to quickly run without waiting for the first interval to be elapsed. This can be useful in certain scenarios where time-sensitive operations need to be performed immediately.

此提交向 gtimer 添加了一个新的“Quick”布尔值,可用于将计时器设置为添加任务后立即执行,而无需等待第一个间隔结束。 这在某些需要立即执行时间敏感操作的场景中很有用。

PS:现在假设我添加一个30分钟执行的任务,则需要30分钟后才能第一次执行!

…sed to set the timer to quickly run without waiting for the first interval to be elapsed. This can be useful in certain scenarios where time-sensitive operations need to be performed immediately.
@codecov-commenter
Copy link

codecov-commenter commented Mar 3, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.21 🎉

Comparison is base (34946f6) 79.96% compared to head (66faf52) 80.18%.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2488      +/-   ##
==========================================
+ Coverage   79.96%   80.18%   +0.21%     
==========================================
  Files         598      597       -1     
  Lines       49570    49688     +118     
==========================================
+ Hits        39641    39841     +200     
+ Misses       7984     7911      -73     
+ Partials     1945     1936       -9     
Flag Coverage Δ
go-1.15-386 80.16% <100.00%> (+0.13%) ⬆️
go-1.15-amd64 80.14% <100.00%> (?)
go-1.16-386 80.14% <100.00%> (+0.13%) ⬆️
go-1.16-amd64 ?
go-1.17-386 80.13% <100.00%> (?)
go-1.17-amd64 80.14% <100.00%> (?)
go-1.18-386 ?

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
os/gtimer/gtimer.go 86.48% <ø> (ø)
os/gtimer/gtimer_timer.go 100.00% <100.00%> (ø)
os/gcron/gcron_schedule_fix.go 81.81% <0.00%> (-9.10%) ⬇️
net/goai/goai_parameter_ref.go 77.77% <0.00%> (-3.89%) ⬇️
contrib/config/kubecm/kubecm_kube.go
contrib/config/kubecm/kubecm.go
contrib/drivers/oracle/oracle.go 79.45% <0.00%> (ø)
util/gconv/gconv_map.go 97.08% <0.00%> (+0.02%) ⬆️
net/goai/goai_shema.go 71.91% <0.00%> (+0.58%) ⬆️
os/gfsnotify/gfsnotify_watcher_loop.go 83.19% <0.00%> (+5.04%) ⬆️
... and 1 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@gqcn
Copy link
Member

gqcn commented Mar 5, 2023

@hinego I've thought about it. Is it better to call your timer function and then add it to timer?

@hinego
Copy link
Contributor Author

hinego commented Mar 6, 2023

@hinego I've thought about it. Is it better to call your timer function and then add it to timer?

I see what you mean, but its need extra coding like this

var timer = gtimer.New()

func test(ctx context.Context) {
	log.Println("test")
	if !added {
		timer.AddSingleton(xxx)
	}
	//or
	timer.AddOnce(xxx)
}

However, by my method,only need set the gtimer.TimerOptions dont need more code.

Like this

var timer = gtimer.New(gtimer.TimerOptions{
	Interval: 100,
	Quick:    true,
})

func init() {
	timer.AddSingleton(context.TODO(), 1*time.Second, test)
	timer.AddSingleton(context.TODO(), 1*time.Second, test2)
	timer.AddSingleton(context.TODO(), 1*time.Second, test3)
}
func test(ctx context.Context) {
	log.Println("test")
}
func test2(ctx context.Context) {
	log.Println("test")
}
func test3(ctx context.Context) {
	log.Println("test")
}

so...

@gqcn gqcn added the feature label Mar 7, 2023
@gqcn
Copy link
Member

gqcn commented Mar 7, 2023

@hinego Please add associated unit testing case for your updates.

@hinego
Copy link
Contributor Author

hinego commented Mar 8, 2023

@hinego Please add associated unit testing case for your updates.

@hinego Please add associated unit testing case for your updates.

added

@hinego
Copy link
Contributor Author

hinego commented Mar 20, 2023

今天用到gtimer.once 时发现一个问题,如果quic时once这种就不适合了

所以要么,再适配一下,把once时不受quick的影响,要么once时不要使用quick模式

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


When I used gtimer.once today, I found a problem. Once is not suitable for quic

So either, adapt it again, and make once unaffected by quick, or don’t use quick mode when once

@gqcn
Copy link
Member

gqcn commented Mar 20, 2023

今天用到gtimer.once 时发现一个问题,如果quic时once这种就不适合了

所以要么,再适配一下,把once时不受quick的影响,要么once时不要使用quick模式

I think it needs no worry about once.

@gqcn gqcn merged commit 0b6798a into gogf:master Mar 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants