Skip to content

Commit d772941

Browse files
authored
feat: add Cancel method to DelayedExecutor for stopping delayed tasks (#74)
1 parent a85b9a2 commit d772941

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

utils/utils.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,14 @@ func (d *DelayedExecutor) Do(key string, execFunc func()) {
116116
}
117117
}
118118

119+
func (d *DelayedExecutor) Cancel(key string) {
120+
if state, ok := d.States.LoadAndDelete(key); ok {
121+
if state.(*DelayedState).Timer != nil {
122+
state.(*DelayedState).Timer.Stop()
123+
}
124+
}
125+
}
126+
119127
func (d *DelayedExecutor) trigger(key string, execFunc func()) {
120128
_, ok := d.States.LoadAndDelete(key)
121129
if !ok {

0 commit comments

Comments
 (0)