Skip to content

Commit e4c9101

Browse files
committed
rename methods
1 parent cc1d7b4 commit e4c9101

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

keeper.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ type HoldToken interface {
3333
// DeadlineContext is the context that will be canceled when the MaxHoldTime is exceeded during the shutdown process.
3434
DeadlineContext() context.Context
3535

36-
// GoListenThenDo is a shortcut that starts a goroutine to listen for the shutdown event, when the shutdown event is triggered, it runs the provided function. After the function execution is completed, the HoldToken will be released.
36+
// DoOnShutdown is a shortcut that starts a goroutine to listen for the shutdown event, when the shutdown event is triggered, it runs the provided function. After the function execution is completed, the HoldToken will be released.
3737
// the context that is passed to the function is the one returned by DeadlineContext method.
38-
GoListenThenDo(func(ctx context.Context))
38+
DoOnShutdown(func(ctx context.Context))
3939

4040
// GoRun is a shortcut that starts a goroutine and run the provided function immediately. After the function execution is completed, the HoldToken will be released.
4141
GoRun(func())
@@ -83,7 +83,7 @@ type KeeperOpts struct {
8383
type ShutdownKeeper struct {
8484
status int32
8585
listeningCtx context.Context
86-
shuttingFunc func()
86+
shutdownFunc func()
8787
tokenReleaseMode TokenReleaseMode
8888
deadlineCtx context.Context
8989
deadlineCancel func()
@@ -116,7 +116,7 @@ func NewKeeper(opts KeeperOpts) *ShutdownKeeper {
116116
keeper := &ShutdownKeeper{
117117
status: statusReady,
118118
listeningCtx: listeningCtx,
119-
shuttingFunc: listeningCancel,
119+
shutdownFunc: listeningCancel,
120120
tokenReleaseMode: tokenReleaseMode,
121121
deadlineCtx: deadlineCtx,
122122
deadlineCancel: sync.OnceFunc(deadlineCancel),
@@ -191,7 +191,7 @@ func (k *ShutdownKeeper) AllocHoldToken() HoldToken {
191191
// StartShutdown initiates the shutdown process.
192192
func (k *ShutdownKeeper) StartShutdown() {
193193
if atomic.CompareAndSwapInt32(&k.status, statusWaiting, statusShutting) || atomic.CompareAndSwapInt32(&k.status, statusReady, statusShutting) {
194-
k.shuttingFunc()
194+
k.shutdownFunc()
195195
}
196196
}
197197

@@ -263,7 +263,7 @@ func (kt *holdTokenImpl) DeadlineContext() context.Context {
263263
return kt.deadlineCtx
264264
}
265265

266-
func (kt *holdTokenImpl) GoListenThenDo(f func(deadlineCtx context.Context)) {
266+
func (kt *holdTokenImpl) DoOnShutdown(f func(deadlineCtx context.Context)) {
267267
go func() {
268268
defer kt.Release()
269269
kt.ListenShutdown()

keeper_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,12 @@ func TestShutdownKeeper_HoldTokens(t *testing.T) {
6464

6565
start := time.Now()
6666
var actual int32
67-
keeper.AllocHoldToken().GoListenThenDo(func(_ context.Context) {
67+
keeper.AllocHoldToken().DoOnShutdown(func(_ context.Context) {
6868
time.Sleep(time.Second)
6969
atomic.AddInt32(&actual, 1)
7070
})
7171

72-
keeper.AllocHoldToken().GoListenThenDo(func(_ context.Context) {
72+
keeper.AllocHoldToken().DoOnShutdown(func(_ context.Context) {
7373
time.Sleep(500 * time.Millisecond)
7474
atomic.AddInt32(&actual, 1)
7575
})
@@ -140,7 +140,7 @@ func TestShutdownKeeper_MaxHoldTime(t *testing.T) {
140140
})
141141

142142
start := time.Now()
143-
keeper.AllocHoldToken().GoListenThenDo(func(_ context.Context) {
143+
keeper.AllocHoldToken().DoOnShutdown(func(_ context.Context) {
144144
time.Sleep(5 * time.Second)
145145
})
146146

@@ -162,7 +162,7 @@ func TestShutdownKeeper_AlwaysHoldMaxTime(t *testing.T) {
162162
})
163163

164164
start := time.Now()
165-
keeper.AllocHoldToken().GoListenThenDo(func(_ context.Context) {
165+
keeper.AllocHoldToken().DoOnShutdown(func(_ context.Context) {
166166
time.Sleep(500 * time.Millisecond)
167167
})
168168
keeper.signalChan <- syscall.SIGINT

0 commit comments

Comments
 (0)