Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. // Callback pattern
  2. function main() {
  3. asyncApi((err, result) => {
  4. if (err !== null) {
  5. console.error(`An Error occurred, ${err.message}`);
  6. } else {
  7. console.log(`The result is ${result}`);
  8. }
  9. });
  10. }
  11.  
  12. // Promise Pattern
  13. function main() {
  14. pAsyncApi()
  15. .then(result => console.log(`The result is ${result}`))
  16. .catch(err => console.error(`An error occured ${err.message}`));
  17. }
  18.  
  19. // Async/Await Pattern
  20. async function main() {
  21. try {
  22. const result = await pAsyncApi();
  23. console.log(`The result is ${result}`);
  24. } catch (e) {
  25. console.error(`An error occured ${e}`);
  26. }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement