Skip to content

Instantly share code, notes, and snippets.

@feliperohdee
Created December 24, 2022 22:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save feliperohdee/68a65c940de5773f1ae16f4de2f080ac to your computer and use it in GitHub Desktop.
Save feliperohdee/68a65c940de5773f1ae16f4de2f080ac to your computer and use it in GitHub Desktop.
promise-all-3.js
const putData = async (data, ms) => {
return new Promise(resolve => {
setTimeout(() => {
resolve(data);
}, ms);
});
};
const clearAll = async () => {
// logic to clear all data
};
try {
const [
result1,
result2,
result3
] = await Promise.all([
putData({
email: 'user@email.com'
}, 1000),
putData({
apiKey: 'api-token'
}, 2000),
putData({
settings: {
accountName: 'John Doe',
accountType: 'Premium'
}
}, 3000)
]);
} catch(err) {
// an error happened and we need to clear all data
await clearAll();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment