mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-09-02 21:15:21 +02:00
nip13: defer cancel() calls.
This commit is contained in:
@@ -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)
|
||||
|
||||
|
@@ -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
|
||||
}()
|
||||
|
Reference in New Issue
Block a user