Async: AsyncFunction์„ iteratee ํ•จ์ˆ˜๋กœ ์‚ฌ์šฉํ•˜๋ฉด iteratee๊ฐ€ ์ •์˜๋˜์ง€ ์•Š์€ ๊ฒƒ์œผ๋กœ ์ „๋‹ฌ๋ฉ๋‹ˆ๋‹ค.

์— ๋งŒ๋“  2017๋…„ 09์›” 26์ผ  ยท  4์ฝ”๋ฉ˜ํŠธ  ยท  ์ถœ์ฒ˜: caolan/async

์–ด๋–ค ๋ฒ„์ „์˜ ๋น„๋™๊ธฐ๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๊นŒ?
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 ํ•ฉ๋‹ˆ๋‹ค.

docs question

๊ฐ€์žฅ ์œ ์šฉํ•œ ๋Œ“๊ธ€

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

๋ชจ๋“  4 ๋Œ“๊ธ€

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

๐Ÿคฆโ€โ™‚๏ธ ๋ฌธ์„œ์˜ ํ•ด๋‹น ๋ถ€๋ถ„์„ ๋” ๋ช…ํ™•ํ•˜๊ฒŒ ์ฝ๋Š” ๊ฒƒ์ด ํ˜„๋ช…ํ–ˆ์„ ๊ฒƒ์ž…๋‹ˆ๋‹ค. ๊ฐ์‚ฌ.

๊ณตํ‰ํ•˜๊ฒŒ, ๊ทธ ์„ค๋ช…์€ ๋ฌธ์„œ ์‚ฌ์ดํŠธ์—์„œ ๊ทธ๋ ‡๊ฒŒ ๋ถ„๋ช…ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค ... ๐Ÿ™„ ๐Ÿ“œ

์‚ฌ์‹ค ๊ฝค ๋ถ„๋ช…ํ•˜๋‹ค๊ณ  ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค. ๋‚˜๋Š” ์ฒ˜์Œ์— ๋ฌธ์„œ๋ฅผ ํ›‘์–ด ๋ณด์•˜๊ณ  ๊ทธ ๋ถ€๋ถ„์„ ๋†“์ณค๋‹ค.

์ด ํŽ˜์ด์ง€๊ฐ€ ๋„์›€์ด ๋˜์—ˆ๋‚˜์š”?
0 / 5 - 0 ๋“ฑ๊ธ‰