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

Refactor fs datastore to us async/await #22

Merged
merged 2 commits into from
May 29, 2019
Merged

Conversation

zcstarr
Copy link

@zcstarr zcstarr commented Feb 22, 2019

I just banged up a quick async/await translation of the js-datastore-fs. I tried to follow ipfs/interface-datastore#25 for guidance. Let me know if this seems right. 3 test fail in this, I believe due to the dependency on datastore core.

I will probably tackle translating that next and then sync the js-ipfs-repo/js-datastore-fs PR's so all test pass.

One thing to note here is that within test, there is a linting error on for await ( x of asyncgenerator){} , which seems spurious, but I might be mistaken here, so if you have insight much appreciated, as well as any comments or corrections. I'm happy to dig in and clean it up!

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 👍

A couple of small things I noticed:

  • In FSDatastore:
    • line 91: there is a mkdirp.sync() that could be asynchronous
    • line 104: the check for the string does not exist could be replace by using an error code (with the err-code library)
  • In a few places we catch an error and throw something else. It's probably worth logging the original error message for the error that was caught - nevermind I see that the original error is encapsulated in the thrown error

})
try {
await fsUnlink(parts.file)
} catch (err) {
Copy link

Choose a reason for hiding this comment

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

Should we ignore the error if it indicates that the file has already been deleted?

}, cb)
], (err) => callback(err))
commit: async () /* : Promise<void> */ => {
await Promise.all((puts.map((put) => this.put(put.key, put.value))))
Copy link

Choose a reason for hiding this comment

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

It may be more efficient to put these in one big Promise.all() instead of two separate ones

done()
})
)
let res = []
Copy link

Choose a reason for hiding this comment

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

"interface-datastore": "~0.6.0",
"mkdirp": "~0.5.1",
"pull-stream": "^3.6.9"
"interface-datastore": "git://github.com/ipfs/interface-datastore.git#refactor/async-iterators",
Copy link
Member

Choose a reason for hiding this comment

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

As the refactor/async-iterators PR was merged and the branch deleted this is outdated and breaks things.

@AuHau AuHau mentioned this pull request May 20, 2019
8 tasks
@AuHau
Copy link
Member

AuHau commented May 28, 2019

Any update on this? interface-datastore has already the async refactor merged and released with 0.7.0, so I believe this is not blocked anymore?

@achingbrain achingbrain mentioned this pull request May 29, 2019
@achingbrain achingbrain merged commit 4ca128c into ipfs:master May 29, 2019
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.

4 participants