Skip to content
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

feat: refactor to use async/await #8

Merged
merged 1 commit into from
Jul 12, 2019
Merged

feat: refactor to use async/await #8

merged 1 commit into from
Jul 12, 2019

Conversation

achingbrain
Copy link
Member

Also upgrades all the deps, moves from ipfs-api to ipfs-http-client and removes a lot of results massaging that is now done in the http client.

@achingbrain
Copy link
Member Author

achingbrain commented Jul 5, 2019

Depends on ipfs/js-ipfsd-ctl#353
Refs ipfs/js-ipfs#1670

Copy link
Contributor

@jacobheun jacobheun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a minor nit with jsdocs.

src/index.js Outdated
@@ -28,54 +23,26 @@ class DelegatedPeerRouting {
* @param {PeerID} id
* @param {object} options
* @param {number} options.maxTimeout How long the query can take. Defaults to 30 seconds
* @param {function(Error, PeerInfo)} callback
* @returns {void}
* @returns {Promise}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @returns {Promise}
* @returns {Promise<PeerInfo>}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Me, personally, I don't like jsdocs and this is a clear example of why.

This module calls this.dht.findPeer which returns a Promise of... a PeerInfo? Now yes, but in the future maybe not and there's nothing to let us know.

That is, we treat them like types and generate documentation from them as if they are accurate but really they are out of date as soon as they've been typed out.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The advantage of this for me is that I can get introspection when I'm writing code, and I don't have to go look at docs or readme's. Resolves/Rejects don't have good support yet in jsdocs. I'd prefer the approach mentioned at jsdoc/jsdoc#1467. In reality, having a return type of promise is redundant due to the function declaration of async. Knowing what's going to be resolved/rejected is the valuable bit.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's nice when this works but it's just too easy for them to get out of date.

In the case above it wouldn't even be the fault of this module - if this.dht.findPeer changed it's return type and we just blindly pass it through there's nothing (like a compiler) to tell us we are breaking our users.

The closest thing we have to automation there is someone opening an issue or sending a PR which is not ideal.

@jacobheun
Copy link
Contributor

Master now has the travis file if you want to rebase.

@achingbrain
Copy link
Member Author

Have rebased & updated the jsdoc. Also removed the git url for ipfsd-ctl as ipfs/js-ipfsd-ctl#353 has been released.

@achingbrain
Copy link
Member Author

Also #7 is quite right - this module doesn't actually appear to do anything.

@jacobheun
Copy link
Contributor

Also #7 is quite right - this module doesn't actually appear to do anything.

Not sure I follow. If you aren't running a DHT or another peer router, you have no way of finding specific peers on the network that you're not connected to. This module allows you to leverage another modules DHT to find a given peer.

#7 is in regards to the interface for peer routing, which is incorrect atm. Peer routing in libp2p uses findPeer as opposed to the interfaces definition of findPeers.

@achingbrain
Copy link
Member Author

I just meant that all it does is call through to dht.findPeer with a timeout - I expected a bit more magic 😉. I guess it does encapsulate the config to connect to the other api though.

@jacobheun
Copy link
Contributor

Ah yeah, it's super trivial, but the nice thing (if you're also running a dht) is you can add it as another peer router to try the delegate node if your dht fails to find a peer.

@alanshaw alanshaw mentioned this pull request Jul 10, 2019
1 task
BREAKING CHANGE: API refactored to use async/await

Also upgrades all the deps, moves from `ipfs-api` to `ipfs-http-client`
and removes a lot of results massaging that is now done in the
http client.
Copy link
Contributor

@jacobheun jacobheun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, codecov drop is due to .aeigr.js line changes being counted

@jacobheun jacobheun merged commit 1827328 into master Jul 12, 2019
@jacobheun jacobheun deleted the async-await branch July 12, 2019 09:08
@jacobheun
Copy link
Contributor

available in v0.3.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants