์ด๋ค ๋ฒ์ ์ ๋น๋๊ธฐ๋ฅผ ์ฌ์ฉํ๊ณ ์์ต๋๊น?
2.5.0
(๋
ธ๋ ๋ฒ์ / ๋ธ๋ผ์ฐ์ ๋ฒ์ )์์ ๋ฌธ์ ๊ฐ ๋ฐ์ํ ํ๊ฒฝ
OS ๋ฒ์ : OS X 10.12.6
๋
ธ๋ ๋ฒ์ : 8.4.0
๋ธ๋ผ์ฐ์ ๋ฒ์ : N / A
๋ญ ํ์ด?
// templateNames is an array of strings
async.map(templateNames, async (templateName, next) => {
let template;
try {
template = await utils.getFile(templateName);
} catch(err) {
next(err);
}
...
// and so on
์ด๋ค ์ผ์ด ์ผ์ด๋๊ธฐ๋ฅผ ๊ธฐ๋ ํ์ต๋๊น?
next
์ ๋ฐ๋ณต ํจ์์
๋๋ค.
์ค์ ๊ฒฐ๊ณผ๋ ๋ฌด์์
๋๊น?
next
์ undefined
๊ฒฐ๊ตญ .then().catch()
๊ตฌ๋ฌธ์ ์ฌ์ฉํ์ฌ ๋ชฉํ๋ฅผ ๋ฌ์ฑํ์ง๋ง AsyncFunction
( ์ฐธ๊ณ : ์ด๊ฒ์ async
์ ์๊ฐ ์๋๋ผ ๊ธฐ๋ณธ AsyncFunction
์ ์ฌ์ฉํ์ฌ ๊ณต์ ํ๊ณ ์ถ์์ต๋๋ค next
)๊ฐ undefined
ํฉ๋๋ค.
async
ํจ์๋ 2.3.0๋ถํฐ ๋ค๋ฅด๊ฒ ์ฒ๋ฆฌ๋๋ฉฐ ์ฝ๋ฐฑ์ด ์ ๋ฌ๋์ง ์์ต๋๋ค. ๋์ ๊ฐ (๋๋ ์ฝ์)์ โโ๋ฐํํ์ญ์์ค. ์ค์ ๋ก, ๊ทํ์ ์์ ์์๋ try
/ catch
์กฐ์ฐจ๋ ๋ฐ์ํ๋ ์ค๋ฅ๊ฐ Async์ ์ํด ํฌ์ฐฉ๋๊ธฐ ๋๋ฌธ์ ํ์ํ์ง ์์ต๋๋ค. ์ด๋ ๊ฒํ๋ฉด ์ฝ๋๊ฐ ์ฝ๊ฐ ๋จ์ํ๋ฉ๋๋ค.
// templateNames is an array of strings
async.map(templateNames, async templateName => {
const template = await utils.getFile(templateName);
...
// and so on
AsyncFunction
๋ฌธ์ : http://caolan.github.io/async/global.html
๐คฆโโ๏ธ ๋ฌธ์์ ํด๋น ๋ถ๋ถ์ ๋ ๋ช ํํ๊ฒ ์ฝ๋ ๊ฒ์ด ํ๋ช ํ์ ๊ฒ์ ๋๋ค. ๊ฐ์ฌ.
๊ณตํํ๊ฒ, ๊ทธ ์ค๋ช ์ ๋ฌธ์ ์ฌ์ดํธ์์ ๊ทธ๋ ๊ฒ ๋ถ๋ช ํ์ง ์์ต๋๋ค ... ๐ ๐
์ฌ์ค ๊ฝค ๋ถ๋ช ํ๋ค๊ณ ์๊ฐํฉ๋๋ค. ๋๋ ์ฒ์์ ๋ฌธ์๋ฅผ ํ์ด ๋ณด์๊ณ ๊ทธ ๋ถ๋ถ์ ๋์ณค๋ค.
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
async
ํจ์๋ 2.3.0๋ถํฐ ๋ค๋ฅด๊ฒ ์ฒ๋ฆฌ๋๋ฉฐ ์ฝ๋ฐฑ์ด ์ ๋ฌ๋์ง ์์ต๋๋ค. ๋์ ๊ฐ (๋๋ ์ฝ์)์ โโ๋ฐํํ์ญ์์ค. ์ค์ ๋ก, ๊ทํ์ ์์ ์์๋try
/catch
์กฐ์ฐจ๋ ๋ฐ์ํ๋ ์ค๋ฅ๊ฐ Async์ ์ํด ํฌ์ฐฉ๋๊ธฐ ๋๋ฌธ์ ํ์ํ์ง ์์ต๋๋ค. ์ด๋ ๊ฒํ๋ฉด ์ฝ๋๊ฐ ์ฝ๊ฐ ๋จ์ํ๋ฉ๋๋ค.AsyncFunction
๋ฌธ์ : http://caolan.github.io/async/global.html