Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Function with a promise
- const doAsyncStuff = () => {
- return new Promise((resolve, reject) => {
- if (stuff) {
- resolve('cool');
- }
- reject('bad');
- });
- };
- // Promise function resolution, old style
- main() {
- doAsyncStuff().then(res => {
- // res === 'cool'
- }).catch(err => {
- // err === 'bad'
- });
- }
- // Promise function resolution, async/await style
- async main() {
- try {
- const isCool = await asyncStuff();
- // isCool === 'cool'
- } catch (err) {
- // err === 'bad'
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement