-
Notifications
You must be signed in to change notification settings - Fork 11
Refactor fs datastore to us async/await #22
Conversation
b872d78
to
43bb286
Compare
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.
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)
- line 91: there is a
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) { |
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.
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)))) |
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.
It may be more efficient to put these in one big Promise.all()
instead of two separate ones
done() | ||
}) | ||
) | ||
let res = [] |
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.
"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", |
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.
As the refactor/async-iterators
PR was merged and the branch deleted this is outdated and breaks things.
Any update on this? |
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!