-
Notifications
You must be signed in to change notification settings - Fork 6
Conversation
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.
Nice! This seems like a pretty clean interface
fetcher.go
Outdated
// crossing block boundaries. The nodes will be typed using the provided prototype. Each matched node is sent to | ||
// the FetchResult channel. | ||
BlockMatchingOfType(ctx context.Context, root ipld.Link, match selector.Selector, ptype ipld.NodePrototype) (<-chan FetchResult, <-chan 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.
Should (both of) the result channels be expected to be closed when this request is done?
Will the error channel be able to yield more than one error? Can FetchResult and errors be yielded intermingled?
Would this perhaps be clearer if this was unified into one channel, and FetchResult just contained either a Result or an 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.
You're last comment is correct. I gave to 2 channels a go, but I think it's just too complicated to explain the behavior and properly process the results. I've changed it to a single channel with an error in the result.
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.
Strike that. @hannahhoward pointed out ipfs/interface-go-ipfs-core#62. The reasoning here makes sense, so I'm keeping the error channel, modifying it so that it's always buffered and closed on completion and then documenting the behavior in the interface.
965ad1c
to
44f845d
Compare
44f845d
to
7ec6d73
Compare
Separation of core and helper methods and better channel behavior This commit was moved from ipfs/go-fetcher@7229dd1
closes #7
Motivation
The fetcher adds many functions to fetch IPLD prime through IPFS. Most of these methods are simply conveniences to provide a simple interface for common tasks. This proliferation of methods will complicate future efforts to extend or replace this library. A better pattern is to provide a few very flexible methods to provide core functionality (
fetcherSession
), give it an interface, then call the rest helper methods and modify them to use this interface.Note: The issue discussed limiting the core to
BlockMatchingOfType
andNodeMatching
. Arguably,BlockOfType
is more core thanBlockMatchingOfType
and in practice either of these requires significant additional complexity to implement from the other (I tried it both ways). Consequently, I've left bothBlockOfType
andBlockMatchingOfType
in the core.What's in this PR
Fetcher
interface for core methods, and renameFetcher
struct tofetcherSession
.Fetcher
as a parameter.