Skip to content
This repository has been archived by the owner on Mar 23, 2023. It is now read-only.

Refactor datastore core to use async/await instead of callbacks #17

Merged
merged 2 commits into from
May 29, 2019

Conversation

zcstarr
Copy link

@zcstarr zcstarr commented Mar 1, 2019

I refactored the package to use async/await as per ipfs/js-ipfs#1670. I added a helper function many that might make sense to move into datastore-interface util, if its generally useful to round robin async iterables. Let me know what you think, happy to jump in and patch up, any feedback greatly appreciated!

Copy link

@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.

Nice work @zcstarr, the code is so much nicer with async/await 👍
I made a couple of small suggestions in the code but overall looks really good. In general I would suggest

async open () /* : void */ {
try {
await (this.stores.map((store) => store.open()))
} catch (err) {
Copy link

Choose a reason for hiding this comment

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

I know this wasn't part of the original code, but I wonder if we should log the error here?

cb()
})
}, callback)
async has (key /* : Key */) /* : Promise<bool> */ {
Copy link

Choose a reason for hiding this comment

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

Would it make sense to do this in parallel? It's a little tricky because you want to return true as soon as you get a true response from a store, but it should be possible with a function from streaming-iterables (maybe transform()?)

each(batches, (b, cb) => {
b.commit(cb)
}, callback)
commit: async () /* : Promise<void> */ => {
Copy link

Choose a reason for hiding this comment

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

Should these run in parallel?

@@ -0,0 +1,9 @@
'use strict'
Copy link

Choose a reason for hiding this comment

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

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