Skip to content

Commit 0261d1f

Browse files
committed
[Go docs] Add info that context is cancelled when batch was ended
1 parent dafdb21 commit 0261d1f

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

batch.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,20 @@ type Options[Resource any] struct {
2222
// By default, 2*MinDuration.
2323
MaxDuration time.Duration
2424
// LoadResource loads resource with given key from a database. Returning an error aborts the batch.
25-
// This function is called in the beginning of each new batch. Context passed as a first parameter
26-
// has a timeout calculated using batch MaxDuration. You can use this information to abort loading resource
27-
// if it takes too long.
25+
// This function is called in the beginning of each new batch.
26+
//
27+
// Context passed as a first parameter has a timeout calculated using batch MaxDuration.
28+
// You can watch context cancellation in order to abort loading resource if it takes too long.
29+
// Context is also cancelled after batch was ended.
2830
//
2931
// By default, returns zero-value Resource.
3032
LoadResource func(_ context.Context, key string) (Resource, error)
3133
// SaveResource saves resource with given key to a database. Returning an error aborts the batch.
32-
// This function is called at the end of each batch. Context passed as a first parameter
33-
// has a timeout calculated using batch MaxDuration. You can use this information to abort saving resource
34-
// if it takes too long (thus aborting the entire batch).
34+
// This function is called at the end of each batch.
35+
//
36+
// Context passed as a first parameter has a timeout calculated using batch MaxDuration.
37+
// You can watch context cancellation in order to abort saving resource if it takes too long
38+
// (thus aborting the entire batch). Context is also cancelled after batch was ended.
3539
//
3640
// By default, does nothing.
3741
SaveResource func(_ context.Context, key string, _ Resource) error

0 commit comments

Comments
 (0)