Advertisement
innot

Promise

Jun 19th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     // async toFulfill
  2.     /**
  3.      *
  4.      * @return {Promise<[(*|undefined), any, any, any, any, any, any, any, any, any]>}
  5.      */
  6.     this.fulfill = async () => {
  7.         if(state && state.toFulfill){
  8.             return Promise.all(state.toFulfill.map(name => {
  9.                 if (toFulfill[name]) {
  10.                     return toFulfill[name]();
  11.                 }
  12.                 return Promise.resolve();
  13.             }))
  14.         }
  15.  
  16.         // return this // return default promise
  17.     };
  18.    
  19.     this.fulfill1 = () => new Promise(r => {
  20.  
  21.         if(state && state.toFulfill){
  22.             Promise.all(state.toFulfill.map(name => {
  23.                 if (toFulfill[name]) {
  24.                     return toFulfill[name]();
  25.                 }
  26.                 return Promise.resolve();
  27.             }))
  28.                 .then(() => {r()})
  29.         } else {
  30.             r()
  31.         }
  32.     });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement