nip13: defer cancel() calls.

This commit is contained in:
fiatjaf
2024-10-18 07:08:47 -03:00
parent 28b05cdd9b
commit b58c4c5516
2 changed files with 5 additions and 2 deletions

View File

@@ -87,6 +87,7 @@ func DoWork(ctx context.Context, event nostr.Event, targetDifficulty int) (nostr
}
ctx, cancel := context.WithCancel(ctx)
defer cancel()
nthreads := runtime.NumCPU()
tagCh := make(chan nostr.Tag)

View File

@@ -79,7 +79,8 @@ func TestDoWorkLong(t *testing.T) {
Content: "It's just me mining my own business",
PubKey: "a48380f4cfcc1ad5378294fcac36439770f9c878dd880ffa94bb74ea54a6f243",
}
ctx, _ := context.WithTimeout(context.Background(), time.Minute)
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()
pow, err := DoWork(ctx, event, difficulty)
if err != nil {
t.Fatal(err)
@@ -114,7 +115,8 @@ func TestDoWorkTimeout(t *testing.T) {
}
done := make(chan error)
go func() {
ctx, _ := context.WithTimeout(context.Background(), time.Millisecond)
ctx, cancel := context.WithTimeout(context.Background(), time.Millisecond)
defer cancel()
_, err := DoWork(ctx, event, 256)
done <- err
}()