-
Notifications
You must be signed in to change notification settings - Fork 7
✨ [parallelisation] Extend the cancel/close store to have various ways of functioning (e.g. parallel, sequential, reverse order, etc.)
#676
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| :sparkles: `[parallelisation]` Extend the cancel/close store to have various ways of functioning (e.g. parallel, sequential, reverse order, etc.) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,13 +25,22 @@ func (s *CloserStore) Len() int { | |
|
|
||
| // NewCloserStore returns a store of io.Closer object which will all be closed concurrently on Close(). The first error received will be returned | ||
| func NewCloserStore(stopOnFirstError bool) *CloserStore { | ||
| option := ExecuteAll | ||
| if stopOnFirstError { | ||
| option = StopOnFirstError | ||
| } | ||
|
Comment on lines
+28
to
+31
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Having an option only represent a positive will help us avoid overwriting options which will simplify option interactions if things get complicated, what do you think?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the overwriting is because the stores cancel and close have fundamentally different behaviours |
||
| return NewCloserStoreWithOptions(option, Parallel) | ||
| } | ||
|
|
||
| // NewCloserStoreWithOptions returns a store of io.Closer object which will all be closed on Close(). The first error received if any will be returned | ||
| func NewCloserStoreWithOptions(opts ...StoreOption) *CloserStore { | ||
| return &CloserStore{ | ||
| store: *newFunctionStore[io.Closer](false, stopOnFirstError, func(_ context.Context, closerObj io.Closer) error { | ||
| store: *newFunctionStore[io.Closer](func(_ context.Context, closerObj io.Closer) error { | ||
| if closerObj == nil { | ||
| return commonerrors.UndefinedVariable("closer object") | ||
| } | ||
| return closerObj.Close() | ||
| }), | ||
| }, append(opts, RetainAfterExecution)...), | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -90,11 +99,26 @@ func (s *CloseFunctionStore) Len() int { | |
| return s.store.Len() | ||
| } | ||
|
|
||
| // NewCloseFunctionStoreStore returns a store closing functions which will all be called concurrently on Close(). The first error received will be returned. | ||
| func NewCloseFunctionStoreStore(stopOnFirstError bool) *CloseFunctionStore { | ||
| // NewCloseFunctionStore returns a store closing functions which will all be called on Close(). The first error received if any will be returned. | ||
| func NewCloseFunctionStore(options ...StoreOption) *CloseFunctionStore { | ||
| return &CloseFunctionStore{ | ||
| store: *newFunctionStore[CloseFunc](false, stopOnFirstError, func(_ context.Context, closerObj CloseFunc) error { | ||
| store: *newFunctionStore[CloseFunc](func(_ context.Context, closerObj CloseFunc) error { | ||
| return closerObj() | ||
| }), | ||
| }, append(options, RetainAfterExecution)...), | ||
| } | ||
| } | ||
|
|
||
| // NewCloseFunctionStoreStore is exactly the same as NewConcurrentCloseFunctionStore but without a typo in the name. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what typo ?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. StoreStore in the name |
||
| func NewCloseFunctionStoreStore(stopOnFirstError bool) *CloseFunctionStore { | ||
| return NewConcurrentCloseFunctionStore(stopOnFirstError) | ||
| } | ||
|
|
||
| // NewConcurrentCloseFunctionStore returns a store closing functions which will all be called concurrently on Close(). The first error received will be returned. | ||
| // Prefer using NewCloseFunctionStore where possible | ||
| func NewConcurrentCloseFunctionStore(stopOnFirstError bool) *CloseFunctionStore { | ||
| option := ExecuteAll | ||
| if stopOnFirstError { | ||
| option = StopOnFirstError | ||
| } | ||
| return NewCloseFunctionStore(option, Parallel) | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.