Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Callback pattern
- function main() {
- asyncApi((err, result) => {
- if (err !== null) {
- console.error(`An Error occurred, ${err.message}`);
- } else {
- console.log(`The result is ${result}`);
- }
- });
- }
- // Promise Pattern
- function main() {
- pAsyncApi()
- .then(result => console.log(`The result is ${result}`))
- .catch(err => console.error(`An error occured ${err.message}`));
- }
- // Async/Await Pattern
- async function main() {
- try {
- const result = await pAsyncApi();
- console.log(`The result is ${result}`);
- } catch (e) {
- console.error(`An error occured ${e}`);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement