-
Notifications
You must be signed in to change notification settings - Fork 336
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: use async/await syntax #411
Conversation
8068adb
to
ea8700e
Compare
@kumar303 I've just updated this PR by rewriting any function that could benefit from the new async/await syntax, above the changes introduced by #424 The coverall report is currently red because of a small helper that I added into "utils/errors.js", I'm going to write a new small test for it asap. Besides the (temporary) coverall report failure, this PR should now ready for a review. |
manifestData = await getValidatedManifest(sourceDir); | ||
} | ||
|
||
let buffer = await zipDir(sourceDir, { |
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.
nit: extra space after the equal sign. Maybe we could add a linting rule for that?
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 think the rule in question is no-multi-spaces
.
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.
👍
added no-multi-spaces
to the enabled eslint rules and removed all the related linting errors in 358c26b
What happens if some code accidentally calls an |
try { | ||
return await connectToFirefox(); | ||
} catch (error) { | ||
if (isErrorWithCode('ECONNREFUSED', error)) { |
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 isErrorWithCode()
, that reads well
I'm excited about this! I got halfway through but I have to end for the day. I'll pick it up tomorrow. |
@kumar303 sorry, I forgot to mention this in the summary of this pull request, and I totally agree that it is an important detail that needs to be discussed in this pull request: An "async function" always returns a Promise, the returned promise is resolved to the value This is very nice, because it means that async function can be composed into Promise chains and mixed with non-async function which returns a Promise (e.g. it is completely valid to put the result of an async function into a
versus
Nevertheless, there is an
|
to be completely fair, what I think is that probably eslint will not be able to detect this kind of mistakes... but I expect that most of them should be caught by the flow type checks :-D e.g. Flow should be able to detect when we are trying to use a promise as the result of "awaiting a promise resolved value", as well as if we are trying to put into a |
992cd56
to
bdb10bf
Compare
…ustom range generator.
bdb10bf
to
4903d57
Compare
|
||
let client; | ||
|
||
while (retriesLeft >= 0) { |
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.
@kumar303 This is the "async/await"-based version of the new defaultRemotePortFinder
(which is the bigger change after the rebase, and it worth a second look from an additional pair of eyes ;-))
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 looks great to me.
try { | ||
client = await connectToFirefox(portToTry); | ||
log.debug(`Remote Firefox port ${portToTry} is in use ` + | ||
`(retries remaining: ${retriesLeft} )`); |
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.
while you're at it, you could fix the extra space in the parentheses around ${retriesLeft}
:) no biggie though, just looks odd in the console.
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.
👍 small tweak just pushed
The goal of this PR is discussing the following proposals:
async / await
syntax to make some of the asynchronous functions nicer to readmake on the sources
The first patch contains a set of experimental changes related to the usage of the
async / await
syntax to make long chains of promises more readable, by configuring babel to transpile them into code that can run across the various supported nodejs versions.This patch ports to the
async / await
syntax only functions where it makes the code nicer and easier to read, and it doesn't port to the new syntax any of the test cases (mostly because it is better to keep the tests unmodified during such a change).The second patch introduces more explicit flow types to be able to give to flow the knowledge needed to check the code in much more detail, e.g. by declaring the types of the objects passed as params, signature of the callbacks etc.The second patch can be augmented with much more explicit flow types definitions, but I wanted to give an initial taste of what it means in terms of the introduced changes before going further in this path. (landed as #424)
As a side note,
async/await
has been recently moved into Stage 4, and so it seems that it will be officially part of the 2017 version of the standard.