-
Notifications
You must be signed in to change notification settings - Fork 1.2k
chore: converts remaining file api methods to async iterators #2517
Conversation
67b9a27
to
d9986ee
Compare
@@ -5,7 +5,7 @@ const all = require('async-iterator-all') | |||
module.exports = function (self) { | |||
// can't use callbackify because if `data` is a pull stream | |||
// it thinks we are passing a callback. This is why we can't have nice things. | |||
return (data, options, callback) => { | |||
return function add (data, options, callback) { |
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.
Why move from arrow func to named func 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.
To have function names in any stack traces emitted making them a teensy bit easier to read.
@@ -49,6 +49,7 @@ describe('files', function () { | |||
const invalidPath = null | |||
const stream = ipfs.getReadableStream(invalidPath) | |||
|
|||
stream.on('data', () => {}) |
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.
Interesting. Something changed for now it requiring to start pumping for the error to be emitted?
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.
In the old implementation, converting the pull stream to a readable stream calls s.sink(read)
in pull-stream-to-stream
which calls drain()
on the next tick which causes data to start flowing, potentially before the consuming code has set up pipes or data event listeners.
I've opened pull-stream/pull-stream-to-stream#7 as this looks like a bug, at least, it's not consistent with the node docs.
The new implementation doesn't do this conversion so doesn't have the same bug.
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.
good catch! 👍
This switches to async iterator version of ipfs.add (introduced to js-ipfs in ipfs/js-ipfs#2517) and ensures Node streams are replaced by deterministic version of readable-stream Closes #757
* fix: /api/v0/add in Brave This switches to async iterator version of ipfs.add (introduced to js-ipfs in ipfs/js-ipfs#2517) and ensures Node streams are replaced by deterministic version of readable-stream Closes #757 * fix(cid): fast finish + allow osx to fail
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.
🥳 woohoo! Just a few feedback points but this look great!
}) | ||
}) | ||
}) | ||
.finally(() => { |
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.
Wow, I did not realise promises had a finally...
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.
Putting the Java into Javascript 😆
ping @achingbrain 🙏 |
Co-Authored-By: Alan Shaw <alan.shaw@protocol.ai>
Depends on ipfs-inactive/js-ipfs-http-client#1124