-
Notifications
You must be signed in to change notification settings - Fork 296
refactor: async iterables #1183
Conversation
80cda06 to
a02bf45
Compare
The interface tests in ipfs-inactive/js-ipfs-http-client#1183 have started throwing `UnhandledPromiseRejection`s for a connection refused error to `/api/v0/shutdown`. This is because `stop` was being called and then called again in `killProcess`. With callbacks this error was smothered but it is now appearing with the promise-only API.
hugomrdias
left a comment
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.
Beautiful ❤️
|
I'm going to back out of the |
lidel
left a comment
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.
@alanshaw after sleeping on it I am bit worried about removing buffered versions of commands like cat.
Instead of
const data = await ipfs.cat(cid)user now needs to ALWAYS wrap it with a helper:
const data = await concat(ipfs.cat(cid))Something feels off here 🤔
I would expect methods like cat to be easy to use, buffered versions (as they are now) and provide separatecatStream for cases where streaming is needed.
Was this discussed before? Did I miss the train?
| }) | ||
|
|
||
| for await (let message of ndjson(toIterable(res.body))) { | ||
| // 3 = QueryError |
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 it possible to extract some of this boilerplate
for await (let message of ndjson(toIterable(res.body)))if (message.Type === 3)- etc
into a function / class?
| } | ||
| }) | ||
|
|
||
| function toCoreInterface (entry) { |
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.
May be worth extracting this into a shared function also
If they want to buffer data into memory then yes that's what they need to do. They definitely don't ALWAYS need to do this! I'd advise against doing so anyway unless you know how much data you're buffering and that it's coming from your local repo. If we provide them, users will just use the non-streaming APIs and be frustrated when things take a long time to yield any results and they get no feedback. For big files, it's necessary to stream data and given the majority of people won't know the size of the file they're retrieving, and are trying to obtain it from a network of poorly connected peers we should provide an API that a) encourages them to do the right thing and not buffer content into memory regardless of the size of the file they're retrieving and b) reduces time to first byte, gives them visibility over progress and allows them to differentiate between the file being unavailable or it being large. On a related point, there's likely to be built in helpers to async iterables soon https://github.com/tc39/proposal-iterator-helpers so you'd be able to |
a83f101 to
2aaf632
Compare
ae85388 to
bd5f0ae
Compare
49d8e34 to
08425af
Compare
08425af to
a27302d
Compare
TLDR;
peer-infoandpeer-idNow that internals are all async/await/iterables and
fetchthe next step is to bubble up that goodness to the core API, removing the multiple stream APIs and removing callback support.I'm also proposing removing
peer-infoandpeer-id, since these drastically increase the bundle size by pulling inlibp2p-crypto, for which 99% of it's capability is unused. In place ofpeer-idwe return aCID, which can easily be converted to aPeerIdinstance via:In place of
peer-infowe return an object{ id: CID, addrs: Multiaddr[] }, which can easily be converted to aPeerInfolike:refs ipfs/js-ipfs#1670
refs ipfs/js-ipfs#2611
refs ipfs-inactive/interface-js-ipfs-core#394
TODO:
addFromFsandaddFromUrland exportglobSourceandurlSourceinsteadinterface-ipfs-coretestsinterface-ipfs-coreDepends on:
BREAKING CHANGE: Callbacks are no longer supported on any API methods. Please use a utility such as
callbackifyon API methods that return Promises to emulate previous behaviour.BREAKING CHANGE:
PeerIdandPeerInfoclasses are no longer statically exported fromipfs-http-clientsince they are no longer used internally.BREAKING CHANGE:
pin.addresults now contain acidproperty (a CID instance) instead of a stringhashproperty.BREAKING CHANGE:
pin.lsnow returns an async iterable.BREAKING CHANGE:
pin.lsresults now contain acidproperty (a CID instance) instead of a stringhashproperty.BREAKING CHANGE:
pin.rmresults now contain acidproperty (a CID instance) instead of a stringhashproperty.BREAKING CHANGE:
addnow returns an async iterable.BREAKING CHANGE:
addresults now contain acidproperty (a CID instance) instead of a stringhashproperty.BREAKING CHANGE:
addReadableStream,addPullStreamhave been removed.BREAKING CHANGE:
lsnow returns an async iterable.BREAKING CHANGE:
lsresults now contain acidproperty (whose value is a CID instance) instead of ahashproperty.BREAKING CHANGE:
files.lsnow returns an async iterable.BREAKING CHANGE:
files.readPullStreamandfiles.readReadableStreamhave been removed.BREAKING CHANGE:
files.readnow returns an async iterable.BREAKING CHANGE:
files.lsPullStreamandfiles.lsReadableStreamhave been removed.BREAKING CHANGE:
files.lsnow returns an async iterable.BREAKING CHANGE:
files.lsresults now contain acidproperty (whose value is a CID instance) instead of ahashproperty.BREAKING CHANGE:
files.lsno longer takes alongoption (in core) - you will receive all data by default.BREAKING CHANGE:
files.statresult now contains acidproperty (whose value is a CID instance) instead of ahashproperty.BREAKING CHANGE:
getnow returns an async iterable. Thecontentproperty value for objects yielded from the iterator is now an async iterable that yieldsBufferListobjects.BREAKING CHANGE:
stats.bwnow returns an async iterable.BREAKING CHANGE:
addFromStreamhas been removed. Useaddinstead.BREAKING CHANGE:
isIPFSis no longer exported from the client, pleasenpm i is-ipfsor include the CDN script tag<script src="https://unpkg.com/is-ipfs/dist/index.min.js"></script>to use this utility in your applications.BREAKING CHANGE:
addFromFshas been removed. Please use the exportedglobSourceutility and pass the result toadd. See the glob source documentation for more details and an example.BREAKING CHANGE:
addFromURLhas been removed. Please use the exportedurlSourceutility and pass the result toadd. See the URL source documentation for more details and an example.BREAKING CHANGE:
name.resolvenow returns an async iterable. It yields increasingly more accurate resolved values as they are discovered until the best value is selected from the quorum of 16. The "best" resolved value is the last item yielded from the iterator. If you are interested only in this best value you could useit-lastto extract it like so:BREAKING CHANGE:
block.rmnow returns an async iterable.BREAKING CHANGE:
block.rmnow yields objects of{ cid: CID, error: Error }.BREAKING CHANGE:
dht.findProvs,dht.provide,dht.putanddht.querynow all return an async iterable.BREAKING CHANGE:
dht.findPeer,dht.findProvs,dht.provide,dht.putanddht.querynow yield/return an object{ id: CID, addrs: Multiaddr[] }instead of aPeerInfoinstance(s).BREAKING CHANGE:
refsandrefs.localnow return an async iterable.BREAKING CHANGE:
object.datanow returns an async iterable that yieldsBufferobjects.BREAKING CHANGE:
pingnow returns an async iterable.BREAKING CHANGE:
repo.gcnow returns an async iterable.BREAKING CHANGE:
swarm.peersnow returns an array of objects with apeerproperty that is aCID, instead of aPeerIdinstance.BREAKING CHANGE:
swarm.addrsnow returns an array of objects{ id: CID, addrs: Multiaddr[] }instead ofPeerInfoinstances.BREAKING CHANGE:
block.statresult now contains acidproperty (whose value is a CID instance) instead of akeyproperty.BREAKING CHANGE:
bitswap.wantlistnow returns an array of CID instances.BREAKING CHANGE:
bitswap.statresult has changed -wantlistandpeersvalues are now an array of CID instances.