From 052bd7c1905f0d92ea03128f2be485331af3e396 Mon Sep 17 00:00:00 2001 From: Lukas Wurzinger Date: Sat, 7 Dec 2024 09:51:27 +0100 Subject: [PATCH] simplify --- upsched/upsched.go | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/upsched/upsched.go b/upsched/upsched.go index 422137e..021c5d4 100644 --- a/upsched/upsched.go +++ b/upsched/upsched.go @@ -67,19 +67,20 @@ func (us UploadScheduler[K]) Prepare(k K, timeout time.Duration, cb func(K, erro return errors.New("upload key already exists") } + d := time.Second * time.Duration(timeout) + + f := func() { + if _, ok := us.m.Get(k); ok { + err := us.Finish(k) + cb(k, err) + } + } + us.m.Set( k, upload{ timeout: timeout, - timer: time.AfterFunc( - time.Second*time.Duration(timeout), - func() { - if _, ok := us.m.Get(k); ok { - err := us.Finish(k) - cb(k, err) - } - }, - ), + timer: time.AfterFunc(d, f), }, )