Skip to content

Commit 0146fa5

Browse files
committed
add shortcut method
1 parent 61e07a2 commit 0146fa5

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

keeper.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,11 @@ func (k *ShutdownKeeper) DeadlineContext() context.Context {
200200
return k.deadlineCtx
201201
}
202202

203+
// DoOnShutdown is just a shortcut for HoldToken's DoOnShutdown method.
204+
func (k *ShutdownKeeper) DoOnShutdown(f func(ctx context.Context)) {
205+
k.AllocHoldToken().DoOnShutdown(f)
206+
}
207+
203208
func (k *ShutdownKeeper) doAllocToken(allocFunc func(releaseCallback func()) HoldToken) HoldToken {
204209
atomic.AddInt32(&k.holdTokenNum, 1)
205210
return allocFunc(sync.OnceFunc(k.doReleaseToken))

keeper_test.go

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

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

73-
keeper.AllocHoldToken().DoOnShutdown(func(_ context.Context) {
73+
keeper.DoOnShutdown(func(_ context.Context) {
7474
time.Sleep(500 * time.Millisecond)
7575
atomic.AddInt32(&actual, 1)
7676
})

0 commit comments

Comments
 (0)