-
Notifications
You must be signed in to change notification settings - Fork 639
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
Async await #1358
base: master
Are you sure you want to change the base?
Async await #1358
Conversation
Result of running https://github.com/sgilroy/async-await-codemod
Result of running the await-promise-chain.js codemod from https://github.com/sgilroy/async-await-codemod
@@ -332,32 +331,33 @@ module.exports = (grunt) => { | |||
.then((tests) => { | |||
grunt.log.writeln('Running click tests in parallel... (this will take a while...)'); | |||
return Promise.all( | |||
tests.map((file) => { | |||
tests.map(async (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 whole clickParallel
task still has a bunch of then
. Why is only this part rewritten?
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 looks like promises which are not returned in a function are not going to be rewritten because that would change the return type to be a Promise
instead of void
.
This is fine in some places like here but we might want do change that in other places.
|
||
return programEvents.dispatch({ event: 'working-tree-changed' }); | ||
} catch (e) { | ||
return this.server.unhandledRejection(e); |
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 unhandledRejection
doesn't seem to return anything, I would remove the return
when it is called;
return this.server.unhandledRejection(e); | |
this.server.unhandledRejection(e); |
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.
Yes, it does not return anyting, the rewrite is just using the same returns as before.
So before
.catch((e) => this.server.unhandledRejection(e));
did also return undefined
.
But I agree we should change that!
.postPromise('/createDir', { dir: this.repoPath() }) | ||
.catch((e) => this.server.unhandledRejection(e)) | ||
.then(() => this.updateStatus()); | ||
.catch((e) => this.server.unhandledRejection(e)); |
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.
Shouldn't this also be in a try/catch?
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.
Yes, looks like catch
es aren't always rewritten.
I started to review a bit, but the diff is so large that it is difficult to check everything. In general, the codemod seems good, but it doesn't seem to remove all promises. |
Also, by changing the UI code to use async/await, we are dropping support for all IE versions. @campersau, @jung-kim, which browsers are currently supported or supposed to be supported? |
@Hirse we had this discussion some months ago over here #1178 (comment) I have currently a lot of work at work so I will probably reviewing PRs at the weekend. |
Oh, right. 😄 I still think we should mention the supported browsers (in the Readme). |
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 reviewed the hole thing made a few changes and fixed a few bugs over here
wmertens/ungit@async-await...campersau:async-await
This also makes the tests pass again.
Maybe splitting the PR into smaller pieces might help reviewing it, e.g. frontend code, backend code, tests.
@@ -332,32 +331,33 @@ module.exports = (grunt) => { | |||
.then((tests) => { | |||
grunt.log.writeln('Running click tests in parallel... (this will take a while...)'); | |||
return Promise.all( | |||
tests.map((file) => { | |||
tests.map(async (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.
It looks like promises which are not returned in a function are not going to be rewritten because that would change the return type to be a Promise
instead of void
.
This is fine in some places like here but we might want do change that in other places.
@@ -133,11 +133,10 @@ class AppViewModel { | |||
); | |||
} | |||
gitSetUserConfig(bugTracking) { |
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.
For example let's change that here.
|
||
return programEvents.dispatch({ event: 'working-tree-changed' }); | ||
} catch (e) { | ||
return this.server.unhandledRejection(e); |
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.
Yes, it does not return anyting, the rewrite is just using the same returns as before.
So before
.catch((e) => this.server.unhandledRejection(e));
did also return undefined
.
But I agree we should change that!
if (err.errorCode != 'merge-failed') this.server.unhandledRejection(err); | ||
try { | ||
if (isRemote && !isLocalCurrent) { | ||
return this.server.postPromise('/branches', { |
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 is actually wrong, because postPromise
does return a promise which isn't awaited and try catched here!
}); | ||
if (isRemote && isLocalCurrent) { | ||
return this.server.postPromise('/reset', { |
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 is actually wrong, because postPromise
does return a promise which isn't awaited and try catched here!
const ammendFlag = amend ? '--amend' : ''; | ||
const allowedEmptyFlag = emptyCommit || amend ? '--allow-empty' : ''; | ||
const isGPGSign = config.isForceGPGSign ? '-S' : ''; | ||
return git( |
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 is actually wrong, because git does return a promise which isn't awaited and try catched here!
// bare repositories don't support `--show-toplevel` since git 2.25 | ||
return { type: 'bare', gitRootPath: repoPath }; | ||
} | ||
return git(['rev-parse', '--show-toplevel'], repoPath).then((topLevel) => { |
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 is actually wrong, because git does return a promise which isn't awaited and try catched here!
try { | ||
await fs.access(config.pluginDirectory); | ||
|
||
return loadPlugins(plugins, config.pluginDirectory); |
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 is actually wrong, because loadPlugins does return a promise which isn't awaited and try catched here!
Also returning here is wrong because this function should return the plugins
instead.
await fs.access(userConfigPath); | ||
|
||
return fs | ||
.readFile(userConfigPath, { encoding: 'utf8' }) |
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 is actually wrong, because readFile does return a promise which isn't awaited and try catched here!
await common.put(req, '/gitignore', { path: testDir, data: 'abc' }); | ||
|
||
const res2 = await common.get(req, '/gitignore', { path: testDir }); | ||
await expect(res2.content).to.be('abc'); |
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 is wrong!
I'll wait to revisit this until #1461 is merged, since it will cause a bunch of conflicts |
The result of running the async-await codemod and some fixes