Js. Chain of promises

let doSmth = () => {
  return new Promise((resolve, reject) => {
    if (Math.random() > 0.5) {
      resolve('doSmth success');    
    }
    else
    {
      reject('doSmthFail');    
    } 
  })
}

let doSmthElse = () => {
    return new Promise((resolve, reject) => {
        if (Math.random() > 0.5) {
            resolve('doSmthElseSuccess')    
          }
          else
          {
            reject('doSmthElseFail');    
          }         

    })
}

doSmth()
.then((result) => {
    console.log(result);
    return doSmthElse();
})
.then((result) => console.log(result))
.catch(e => console.log(e));
This entry was posted in Без рубрики. Bookmark the permalink.