Skip to content
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

Use async/await in Rollup scripts #11669

Merged
merged 1 commit into from
Nov 27, 2017
Merged

Conversation

gaearon
Copy link
Collaborator

@gaearon gaearon commented Nov 27, 2017

Removes some boilerplate since we depend on Node 8 anyway.
Best viewed with ?w=1.

await createBundle(bundle, FB_DEV);
await createBundle(bundle, FB_PROD);
await createBundle(bundle, RN_DEV);
await createBundle(bundle, RN_PROD);
Copy link
Contributor

Choose a reason for hiding this comment

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

Woah. I've never seen await in a loop before. 😻

return Promise.resolve();
}
// Run them serially for better console output
// and to avoid any potential race conditions.
Copy link
Contributor

@bvaughn bvaughn Nov 27, 2017

Choose a reason for hiding this comment

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

This comment might be nice to move up to line ~446, for the whole rimraf callback, since we also execute the first few create* tasks serially.

Edit: Actually now that I look again, I'm pretty sure we could just leave the comment here and parallelize the above few tasks 😄 We were running them in serial before but I don't think those need to be. (Not that it would make a bit difference. Those tasks should be super fast.)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't mind parallelizing them but I'm not 100% sure they're free of race conditions. I wouldn't both anyway tbh since they're really fast as you said.

if (syncFbsource) {
await syncReactNative(join('build', 'react-native'), syncFbsource);
await syncReactNativeRT(join('build', 'react-rt'), syncFbsource);
await syncReactNativeCS(join('build', 'react-cs'), syncFbsource);
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: We could wrap these in a Promise.all (not that it would make a big diff, should be fast either way)

Copy link
Contributor

Choose a reason for hiding this comment

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

The build script originally did exactly this but it made the output unreadable (the different bundle errors/warnings were spat out over each other) and there win wasn't actually that of a win in performance as the work is mostly CPU intensive, not IO intensive.

Copy link
Contributor

Choose a reason for hiding this comment

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

That's for the create-bundle steps (below). The sync steps here just copy files. They should be okay to do in parallel. (They don't even log anything, so they wouldn't cause unreadable output.)

But, it wouldn't make a big diff in terms of performance since they're just copying a few files. So it's a "nit" 😄

Copy link
Contributor

@bvaughn bvaughn left a comment

Choose a reason for hiding this comment

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

I scanned this pretty quickly. Didn't actually run it. I trust you. 😄

Love the async/await cleanup!

@gaearon gaearon merged commit a65a8ab into facebook:master Nov 27, 2017
@gaearon gaearon deleted the async-build branch November 27, 2017 17:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants