Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. const onGatherResultsError = e => {
  2. console.error('Failed to get results, cancelling message.')
  3. throw e;
  4. }
  5.  
  6. const onSendResultsError = e => {
  7. console.error('Failed to send results to the mothership')
  8. throw e;
  9. }
  10.  
  11. const getMessage = (result : number) => pAsyncDoSomethingWithResult(result).catch(onSendResultsError);
  12.  
  13. function reportToMotherShipPromise() {
  14. console.log(`Sending results to the mother ship...`);
  15.  
  16. return pAsyncApi()
  17. .catch(onGatherResultsError)
  18. .then(getMessage)
  19. .then((message) => console.log(`Message from the mothership: ${message}`));
  20. }
  21.  
  22. async function reportToMotherShipAsync() {
  23. console.log(`Sending results to the mothership...`);
  24.  
  25. const result = await pAsyncApi().catch(onGatherResultsError);
  26. const message = await pAsyncDoSomethingWithResult(result).catch(onSendResultsError);
  27.  
  28. console.log(`Message from the mothership : ${message}`);
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement