-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
refactor(fileList): refactor with async/await #3247
Conversation
lib/file-list.js
Outdated
@@ -74,7 +74,7 @@ class FileList { | |||
return | |||
} | |||
|
|||
return Promise | |||
const files = await Promise | |||
.filter(mg.found, (path) => { |
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.
This array mg.found
and the function are synchronous, correct?
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.
I rewrote this code, please check once again
lib/file-list.js
Outdated
@@ -95,13 +95,12 @@ class FileList { | |||
return this._preprocess(file).then(() => file) |
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.
The map()
operates on a sync array, returning either a sync array or an array of promises. I guess sync Array.map()
works fine for that somewhat funky operation. It would be less funky if we return Promise.resolve(file)
in the nocache
branch.
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.
I rewrote this code, please check once again
|
||
if (_.isEmpty(files)) { | ||
log.warn(`All files matched by "${pattern}" were excluded or matched by prior matchers.`) | ||
} | ||
}) | ||
.then(() => { |
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.
The then
resolution function is confusing and which promise chain we are resolving is confusing: can we find a better way? At least removing a nesting level might help.
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.
Unfortunately I don't have now idea how to rewrite it
No description provided.