-
-
Notifications
You must be signed in to change notification settings - Fork 5
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
Add thread-safe multi error implementation #2
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Matej Gera <matejgera@gmail.com>
Signed-off-by: Matej Gera <matejgera@gmail.com>
Signed-off-by: Matej Gera <matejgera@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I remember commenting about upstreaming! 🚀
testutil.NotOk(t, func() error { | ||
return e.Err() | ||
}()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, can't this be
testutil.NotOk(t, func() error { | |
return e.Err() | |
}()) | |
testutil.NotOk(t, e.Err()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
What about moving to concurrency safe impl only?
@@ -19,12 +19,11 @@ | |||
// | |||
// Example 3: | |||
// | |||
// func CloseAll(closers []io.Closer) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this right indent?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
// NilOrMultiSyncError is a thread-safe implementation of NilOrMultiError. | ||
// It allows combining multiple errors into one. | ||
type NilOrMultiSyncError struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we don't want to make the normal implementation concurrency safe 🤔 I don't think it introduces worth noting overhead... The only risk is when somebody would like to have different synchronization techniques that works for them, then they would need to reimplement all.. but sounds like rare use case.
Otherwise another option is to have different package..
I think for me it would make more sense to have ONLY gorotoutine safe implementation here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it depends on what use cases there are out in the wild, but I'd agree having one implementation and documenting that it's concurrency safe so it's clear for the users is the way to go. I'll prepare the changes.
I would vote for having just concurrency safe code for I would do it (: cc @saswatamcode @matej-g |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have to revisit merror. https://pkg.go.dev/errors@master#Join entered and it might mean we can drop merror completely.
This is directly inspired by @fpetkovski's work in thanos-io/thanos#5420 (comment).
This PR adds a thread-safe implementation of the
NilOrMultiError
calledNilOrMultiSyncError
. PR provides tests as well.Another small fix in this PR is to unify the method receivers
NilOrMultiError
to use pointers.