mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-09-13 11:52:34 +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)
|
ctx, cancel := context.WithCancel(ctx)
|
||||||
|
defer cancel()
|
||||||
nthreads := runtime.NumCPU()
|
nthreads := runtime.NumCPU()
|
||||||
tagCh := make(chan nostr.Tag)
|
tagCh := make(chan nostr.Tag)
|
||||||
|
|
||||||
|
@@ -79,7 +79,8 @@ func TestDoWorkLong(t *testing.T) {
|
|||||||
Content: "It's just me mining my own business",
|
Content: "It's just me mining my own business",
|
||||||
PubKey: "a48380f4cfcc1ad5378294fcac36439770f9c878dd880ffa94bb74ea54a6f243",
|
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)
|
pow, err := DoWork(ctx, event, difficulty)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
@@ -114,7 +115,8 @@ func TestDoWorkTimeout(t *testing.T) {
|
|||||||
}
|
}
|
||||||
done := make(chan error)
|
done := make(chan error)
|
||||||
go func() {
|
go func() {
|
||||||
ctx, _ := context.WithTimeout(context.Background(), time.Millisecond)
|
ctx, cancel := context.WithTimeout(context.Background(), time.Millisecond)
|
||||||
|
defer cancel()
|
||||||
_, err := DoWork(ctx, event, 256)
|
_, err := DoWork(ctx, event, 256)
|
||||||
done <- err
|
done <- err
|
||||||
}()
|
}()
|
||||||
|
Reference in New Issue
Block a user