Skip to content
This repository was archived by the owner on Jul 21, 2023. It is now read-only.

refactor: use async datastore #140

Merged
merged 4 commits into from
Aug 16, 2019
Merged

Conversation

jacobheun
Copy link
Contributor

BREAKING CHANGE: This change requires datastores that comply with [email protected] or later.

This refactors internal usage of datastore to use the async api. I also bumped aegir and fixed linting. Many of the rules for require-async are ignored at the moment, they should be removed once the full conversion is done.

Note: the libp2p-record update is the last dependency needed to convert to full async/await.

BREAKING CHANGE: The DHT now requires its datastore to have
a promise based api, instead of callbacks. Datastores that use
ipfs/[email protected] or later should be used.
https://github.com/ipfs/interface-datastore/releases/tag/v0.7.0
some rules have been ignored until the full async/await migration has completed
Copy link
Contributor

@dirkmc dirkmc left a comment

Choose a reason for hiding this comment

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

Great news! LGTM 🎉

@jacobheun jacobheun requested a review from vasco-santos August 14, 2019 14:52
Copy link
Member

@vasco-santos vasco-santos left a comment

Choose a reason for hiding this comment

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

Awesome Jacob!
Just found some minor issues with this

@@ -33,7 +33,7 @@ module.exports = (dht) => {
const dsKey = utils.bufferToKey(cid.buffer)

parallel([
Copy link
Member

Choose a reason for hiding this comment

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

what do you think on removing this async/parallel and using Promise.all with promisify for dht._betterPeersToQuery(msg, peer, cb)? We are converting to promises to callbacks here, and it would ease in the future to just remove the promisify from the last task

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, I can migrate the internals of this. I was originally trying to avoid touching too much other than the datastore, but I can go ahead and refactor this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I created a new getProvidersAsync method that uses all the existing async methods, so no promisify is needed. getProviders now calls that with promise-to-callback support, so when we refactor internally we can just do a full swap out of those.

@jacobheun jacobheun requested a review from vasco-santos August 16, 2019 10:26
Copy link
Member

@vasco-santos vasco-santos left a comment

Choose a reason for hiding this comment

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

LGTM

@vasco-santos vasco-santos merged commit daf9b00 into master Aug 16, 2019
@vasco-santos vasco-santos deleted the refactor/async-datastore branch August 16, 2019 10:32
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants