SHARE
TWEET

Untitled

a guest Oct 23rd, 2019 92 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Callback pattern
  2.  
  3. function reportToMotherShip(callback: GenericAsyncCallback<Error, never>) {
  4.     console.log(`Sending results to the mothership...`);
  5.  
  6.     asyncApi((error, result) => {
  7.         if (error) {
  8.             console.error(`Failed to get results, cancelling message.`);
  9.             callback(error);
  10.         } else {
  11.             asyncDoSomethingWithResult(result, (error, message) => {
  12.                 if (error) {
  13.                     console.error(`Failed to send results to the mothership.`)
  14.                     callback(error);
  15.                 } else {
  16.                     console.log(`Message from the mothership: ${message}`);
  17.                     callback(null);
  18.                 }
  19.             })
  20.         }
  21.     })
  22. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top