Created
April 27, 2023 10:45
-
-
Save KoljaL/1ec144fcd9650b3d38e0b662c5208ba0 to your computer and use it in GitHub Desktop.
just a function to imitate a slow promise
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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