프로미스 체이닝방식
function test() {
fetch("https://api.testdomain.com")
.then(response => {
// do something
})
.catch(error => {
//do something
});
}
에이싱크 어웨잇
async function test() {
try {
const response = await fetch("...url...")
// do something
} catch (error) {
// handle error
}
}
==========================
또다른예)
프로미스 체이닝방식
function test() {
return dosomethingAsync()
.then(hello => doAsync2(hello))
.then(world => doAsync3(world))
.then(foo => doAsync4(foo))
.then(bar => doAsync5(bar))
}
에이싱크 어웨잇
async function test() {
const hello = await dosome1();
const world = await dosome2(hello);
const foo = await dosome3(world);
const bar = await dosome4(foo);
await dosome5(bar);
}
============================
프로미스 체이닝 방식은
then하고 그 생명주기가 끝이나는데,
에이싱크방식은
계속 어느곳에서도 다시쓰이는게 가능하다.
쓸일이 없는데도,,,ㅜㅜ