We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโll occasionally send you account related emails.
Already on GitHub? Sign in to your account
๋ด๊ฐ ์์ฑํ ์ฝ๋
async getBoardComments(id: number) { try { const comments = await this.commentRepository.find({ board_id: id }); if (comments) { const user = comments.map( async (el) => { return await this.userRepository.findOne({ id: el.user_id }); }), ); console.log(user, 'user'); } } catch (error) { return error; }
์ฐพ์๋ณด๋ ์ฝ๋ฐฑํจ์์ async๊ฐ ๋ค์ด๊ฐ๋ฉด , Array.map์ ์ฒ๋ฆฌ๋์ง ์์ Promise์ ๋ฐฐ์ด์ returnํ๋ค๊ณ ํ๋ค. pending์ํ๋ resolve ์ํ๋ ์๋๊ณ reject ์ํ๋ ์๋๋ค. ๋ฐ๋ผ์ Promise.all()์ ์ ์ฉ์์ผ์ฃผ๋ฉด resolve๋ ๊ฐ๋ค์ ๋ณผ ์ ์๋ค.
async getBoardComments(id: number) { try { const comments = await this.commentRepository.find({ board_id: id }); if (comments) { const user = await Promise.all( comments.map( async(el) => { return await this.userRepository.findOne({ id: el.user_id }); }), ); console.log(user, 'user'); } } catch (error) { return error; }
์ ์์ ์ผ๋ก ๋ฐ์ดํฐ๋ฅผ ๊ฐ์ ธ์ค๋๊ฑธ ์ ์ ์๋ค.
The text was updated successfully, but these errors were encountered:
soyoung931014
No branches or pull requests
์ค๋์ ์ด๋ป๊ฒ ํ๋ก์ ํธ์ ๊ธฐ์ฌํ๋์?
์ค๋์ ํ๋ก์ ํธ์์ ๊ธฐ์ตํ ๋งํ ๋ถ๋ถ์ด ์๋์?
๋น๋๊ธฐ ํจ์ ์์์ map๋ฉ์๋๋ฅผ ์ด์ฉํด ๋ฐฐ์ด ๊ฐ์ ์ํํ๋ คํ๋๋ ์๋์ ๊ฐ์ ๋ฐ์ดํฐ๋ฅผ ๊ฐ์ง๊ณ ์ค์ง ๋ชปํ๋ ๋ฌธ์ ๊ฐ ์๊ฒผ๋ค.
๋ด๊ฐ ์์ฑํ ์ฝ๋
์ฐพ์๋ณด๋ ์ฝ๋ฐฑํจ์์ async๊ฐ ๋ค์ด๊ฐ๋ฉด , Array.map์ ์ฒ๋ฆฌ๋์ง ์์ Promise์ ๋ฐฐ์ด์ returnํ๋ค๊ณ ํ๋ค. pending์ํ๋ resolve ์ํ๋ ์๋๊ณ reject ์ํ๋ ์๋๋ค. ๋ฐ๋ผ์ Promise.all()์ ์ ์ฉ์์ผ์ฃผ๋ฉด resolve๋ ๊ฐ๋ค์ ๋ณผ ์ ์๋ค.
ํค๊ฒฐ: Promise.all()์ ์ฉ
์ ์์ ์ผ๋ก ๋ฐ์ดํฐ๋ฅผ ๊ฐ์ ธ์ค๋๊ฑธ ์ ์ ์๋ค.
๋ด์ผ์ ํ๋ก์ ํธ์ ๊ธฐ์ฌํ๊ธฐ ์ํด ๋ฌด์์ ํด์ผ ํ๋์?
The text was updated successfully, but these errors were encountered: