Skip to content

Instantly share code, notes, and snippets.

@KoljaL
Created April 27, 2023 10:45
Show Gist options
  • Save KoljaL/1ec144fcd9650b3d38e0b662c5208ba0 to your computer and use it in GitHub Desktop.
Save KoljaL/1ec144fcd9650b3d38e0b662c5208ba0 to your computer and use it in GitHub Desktop.
just a function to imitate a slow promise
let color = 'color: LimeGreen;';
let ms = performance.now();
async function doAPromise(success, timeout) {
return new Promise((resolve, reject) => {
setTimeout(() => {
if (success) {
resolve();
console.log('%cPromise resolved', color, ms);
} else {
reject({ message: 'Promise rejected' });
}
}, timeout);
}).then(function (result) {
return 'your data';
});
}
async function asyncLoadData(bool, timeout) {
try {
return await doAPromise(bool, timeout);
} catch (e) {
return 'no data';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment