Skip to content

Conversation

@paulirish
Copy link
Member

fixes #14302

not trying to get fancy. these are pretty unique ports.

Comment on lines 260 to 266
await Promise.allSettled(servers.map(s => s.listen(s._port, 'localhost'))).then(outcomes => {
if (outcomes.every(o => o.status === 'fulfilled')) return;
if (outcomes.every(o => o.reason.message.includes('already'))) {
return console.warn('😧 Server already up. Continuing…');
}
console.error(outcomes.map(o => o.reason));
});
Copy link
Contributor

Choose a reason for hiding this comment

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

For readability, will this work?

Also we should probably throw an error if the servers fail for an unknown reason

Suggested change
await Promise.allSettled(servers.map(s => s.listen(s._port, 'localhost'))).then(outcomes => {
if (outcomes.every(o => o.status === 'fulfilled')) return;
if (outcomes.every(o => o.reason.message.includes('already'))) {
return console.warn('😧 Server already up. Continuing…');
}
console.error(outcomes.map(o => o.reason));
});
const outcomes = await Promise.allSettled(servers.map(s => s.listen(s._port, 'localhost')));
if (outcomes.some(o => o.status === 'rejected')) {
if (outcomes.every(o => o.reason.message.includes('already'))) {
console.warn('😧 Server already up. Continuing…');
} else {
console.error(outcomes.map(o => o.reason));
throw new Error('One or more servers did not start correctly');
}
}
return servers

Copy link
Member Author

Choose a reason for hiding this comment

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

your await flow is definitely better. and fixes the error throwing. (i was ending up with an unhandled rejection previously)

i do still prefer the style of my two every()s, but whatever. definitely not a big deal.

Copy link
Member Author

Choose a reason for hiding this comment

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

@adamraine thanks for writing out the suggestion! :) so clean.

Copy link
Collaborator

@connorjclark connorjclark left a comment

Choose a reason for hiding this comment

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

Approval w/ Adam's suggestions.

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.

yarn smoke should work when yarn static-server is first called manually

4 participants