-
Notifications
You must be signed in to change notification settings - Fork 9
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
fix: limit concurrent HTTP requests (backport for 0.2.x) #17
fix: limit concurrent HTTP requests (backport for 0.2.x) #17
Conversation
This is a backport of the fix from libp2p#16 that works with 0.2.x License: MIT Signed-off-by: Marcin Rataj <[email protected]>
src/index.js
Outdated
this.dht.findProvs(key.toString(), { | ||
timeout: `${options.maxTimeout}ms` // The api requires specification of the time unit (s/ms) | ||
}, callback) | ||
).catch(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.
I don't know exactly how promisify-es6
works under the hood, does it call callback as well as return a promise? I would have thought it did one or the other.
Maybe we can make this a bit easier to understand as well as eliminate any doubt?
this._httpQueue.add(() =>
this.dht.findProvs(key.toString(), {
timeout: `${options.maxTimeout}ms` // The api requires specification of the time unit (s/ms)
})
).then(res => callback(null, res), 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.
iiuc if callback is present, promisify-es6
will call function as-is; if not, it will return a Promise that injects callback as the last argument before calling the thing
promisify-es6/index.js#L31-L32
Should work the same, so I've switched to your version in 91dcbb7
src/index.js
Outdated
], (err) => callback(err)) | ||
this._httpQueueRefs.add(() => | ||
this.refs(key.toString(), { recursive: false }, (err, res) => callback(err)) | ||
).catch(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.
Same 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.
That's odd: last test (provide
) stop passing if I move callback call to the outside:
this._httpQueueRefs.add(() =>
this.refs(key.toString(), { recursive: false })
).then(res => callback(null, res), callback)
makes tests hang:
6 passing (22s)
1 failing
1) DelegatedContentRouting
provide
should be able to register as a content provider to the delegate node:
Error: Timeout of 20000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (/home/lidel/project/js-libp2p-delegated-content-routing/test/index.spec.js)
Bit late on my end, so I can't tell if it is a bug somewhere, or just me being tired.
Thoughts?
License: MIT Signed-off-by: Marcin Rataj <[email protected]>
License: MIT Signed-off-by: Alan Shaw <[email protected]>
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.
Looks good, I'll get a release out for 2.x
0.2.4 is on the webs! |
This is a backport of the fix from #16 that works with 0.2.x.
The goal is to include the fix in latest js-ipfs release (without waiting for async/await changes to be propagated to js-libp2p)
cc @alanshaw @jacobheun