- ์์ ์ ํ๋ก๊ทธ๋จ์ ๋น๋๊ธฐ ์์๋ฅผ ์, ์ด๋ป๊ฒ ์ถ๊ฐํด์ผํ๋์ง๋ฅผ ์์์ผ ํ๋ค.
- ์ผ๋ฐ์ ์ธ ํ๋ก๊ทธ๋จ chunk ๋จ์๋ ํจ์
-
ํธ์คํ ํ๊ฒฝ
์๋ฐ์คํฌ๋ฆฝํธ ์์ง์ ํธ์คํ ํ๊ฒฝ์์ ์คํ๋๋ค. ๋ธ๋ผ์ฐ์ , ๋ ธ๋js ๋ฑ์์ ์คํ์ด ๋๋ค. ์ด ํธ์คํ ํ๊ฒฝ์ ๊ณตํต์ ์ธ ํน์ง์
์ค๋ ๋๊ฐ์ด๋ฒคํธ ๋ฃจํ๋ผ๋ ๋ฉ์ปค๋์ฆ์ ๊ฐ๊ณ ์๋ค๋ ๊ฒ์ด๋ค. -
์ด๋ฒคํธ ๋ฃจํ
์ด๋ฒคํธ ๋ฃจํ๋ ๋งค ์๊ฐ ์๋ฐ์คํฌ๋ฆฝํธ ์์ง์ ํธ์ถํ์ฌ, ํ๋ก๊ทธ๋จ์ chunk๋ค์ ์คํ์ํฌ ์ ์๊ฒ ํ๋ค.
But the one common โthreadโ (thatโs a not-so-subtle asynchronous joke, for what itโs worth) of all these environments is that they have a mechanism in them that handles executing multiple chunks of your program over time, at each moment invoking the JS engine, called the event loop.
-
tick
์ด๋ฒคํธ ๋ฃจํ๊ฐ ๋งค iteration ๋ง๋ค, ์ด๋ฒคํธ๋ฅผ ๊บผ๋ด์ ์คํ์ํจ๋ค. ์ด iteration์
tick์ด๋ผ๊ณ ํ๋ค. ์ด๋ฒคํธ๋ ์ฝ๋ฐฑํจ์์ด๋ค.setTimeout()์ ํ์ด๋จธ ํจ์์ผ ๋ฟ์ด๊ณ , ์ฝ๋ฐฑํจ์๋ฅผ ์ด๋ฒคํธ ํ์ ๋ฃ๋ ๊ฒ์ ํธ์คํ ํ๊ฒฝ์ด๋ค.
๐ก ์ ๋ฆฌ
- ์๋ฐ์คํฌ๋ฆฝํธ ์์ง: ํ๋ก๊ทธ๋จ์ chunk๋ฅผ ์คํ์ํค๋ ์คํ๊ธฐ
- ์ด๋ฒคํธ ๋ฃจํ: ๊ทธ ์์ง์ ์คํ์ํค๋๊ฒ ์ด๋ฒคํธ ๋ฃจํ. ์ด๋ฒคํธ ์ค์ผ์ฅด๋งํ๊ณ , ์๋ฐ์คํฌ๋ฆฝํธ ์์ง์ด ์ด๋ฒคํธ๋ฅผ ์คํ์ํค๋๋ก ํ๋ค.
- tick๋ง๋ค ์ด๋ฒคํธ ๋ฃจํ๊ฐ ์ด๋ฒคํธ๋ฅผ ์คํ์ํด
-
์์ ์คํ - Run To Complete
์๋ฐ์คํฌ๋ฆฝํธ๋ ์ฑ๊ธ ์ค๋ ๋์ด๋ฏ๋ก, ํจ์ ๋ด๋ถ์ ์ฝ๋๋ ์์์ (atomic)์ด๋ค. ํ ํจ์์ ์คํ์ด ๋๋ ํ, ๋ค๋ฅธ ํจ์๊ฐ ์คํ๋๋ค๋ ๊ฒ์ด๋ค. ์ด๋ฅผ
์์ ์คํ(run-to-complete)์ด๋ผ๊ณ ํ๋ค. -
Race Condition
์๋ฐ์คํฌ๋ฆฝํธ๋ ์์ ์คํ์ด์ง๋ง, ํจ์ ์คํ ์์์ ๋ฐ๋ผ ๊ฒฐ๊ณผ๊ฐ ๋ฌ๋ผ์ง ์ ์๋ค(ํจ์ ์์์ ๋ฐ๋ฅธ ๋น๊ฒฐ์ ์ฑ). ์ด๋ฅผ race condition์ด๋ผ๊ณ ํ๋ค.
์ฐธ๊ณ
-
you don't know js - ๋น๋๊ธฐ์ ์ฑ๋ฅ (์นด์ผ ์ฌ์จ)