Promise

Web Development assistant·2024년 1월 11일
0

# javascript

목록 보기
34/36
const printMyName = name => {console.log(name)};
let count = 0;
const getPromise = (seconds) => new Promise((resolve, reject)=>{
  setTimeout(()=>{
    resolve(printMyName(`ttest ${++count}`));
  }, seconds * 1000)
});

console.log('---zero then---');
getPromise(1)
  .then((res)=>{
    console.log('---first then---');
    return getPromise(2);
}).then((res)=>{
    console.log('---second then---');
    return getPromise(2);
}).then((res)=>{
  console.log('---thrid then---');
  return getPromise(2);
}).then((res)=>{
  console.log('---forth then---');
});

0개의 댓글