-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
chore: return errors using channels and not embedded in result type #10527
base: master
Are you sure you want to change the base?
Conversation
// } | ||
// fmt.Println("Dir name:", dirEnt.Name) | ||
// } | ||
func LsIter(ctx context.Context, api UnixfsAPI, p path.Path, opts ...options.UnixfsLsOption) iter.Seq2[DirEntry, 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.
This is implemented to operate on any UnixfsAPI
since their Ls
should all work the same. Is this a good assumption / implementation, or should each UnixfsAPI
provide its own LsIter
?
LGTM although improvement is marginal if this was already working code, with the side effect of altering CoreAPI (not sure if anyone builds anything on top of it other than Kubo itself). I personally don't like the new pattern much more than the old one. Something like
For me, the best pattern would be APIs like
The implementation of Anyways this is just passing work around our own internal code, so it's all mostly the same. |
core/coreapi/unixfs.go
Outdated
errOut := make(chan error, 1) | ||
errOut <- err | ||
close(errOut) | ||
out := make(chan coreiface.DirEntry) | ||
close(out) | ||
return out, errOut |
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.
This kind of blocks are very ugly and are needed all over the place. Could we live with returning nil directly for the out
channel?
Thank you for the review. This PR was a much as a exploration to find a more preferable pattern as to satisfy the original issue. I really agree with
and also, let the caller decide whether or not the function should be called asynchronously. The one benefit this PR does have is not having to wait on both ctx and err chan in case err chan is not read, but that is not really important with regart to the above statement. I will take another pass over this to incorporate your feedback. |
Asynchronous functions should return errors over channels instead of embedding the error in the result type. Closes #9974
44d91ab
to
89890b4
Compare
Asynchronous functions should return errors over channels instead of embedding the error in the result type.
Closes #9974