Atomics.waitAsync()
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
Atomics.waitAsync()
์ ์ ๋ฉ์๋๋ ๊ณต์ ๋ฉ๋ชจ๋ฆฌ ์์น์์ ๋น๋๊ธฐ์ ์ผ๋ก ๋๊ธฐํ๊ณ Promise
๋ฅผ ๋ฐํํฉ๋๋ค.
Atomics.wait()
์๋ ๋ค๋ฅด๊ฒ, waitAsync
๋ ๋
ผ ๋ธ๋กํน์ด๋ฉฐ ๋ฉ์ธ ์ค๋ ๋์์ ์ฌ์ฉํ ์ ์์ต๋๋ค.
์ฐธ๊ณ :
์ด ์์
์ ์ค์ง ๊ณต์ ๋ Int32Array
ํน์ BigInt64Array
์์๋ง ๋์ํฉ๋๋ค.
๊ตฌ๋ฌธ
Atomics.waitAsync(typedArray, index, value)
Atomics.waitAsync(typedArray, index, value, timeout)
๋งค๊ฐ๋ณ์
typedArray
-
๊ณต์ ๋
Int32Array
ํน์BigInt64Array
. index
-
typedArray
์์์ ๋๊ธฐํ๊ณ ์๋ ์ธ๋ฑ์ค. value
-
ํ ์คํธํ ๊ธฐ๋๊ฐ.
timeout
Optional-
๋๊ธฐ ์๊ฐ(๋ฐ๋ฆฌ์ด). ์๊ฐ์ด ๋ช ์๋์ง ์์ผ๋ฉด
Infinity
์ ๋๋ค.
๋ฐํ ๊ฐ
๋ค์ ์์ฑ์ ๊ฐ์ง Object
.
async
value
์์ฑ์ดPromise
์ธ์ง ์๋์ง๋ฅผ ๋ํ๋ด๋ ๋ถ์ธ์ ๋๋ค.
value
async
๊ฐfalse
์ด๋ฉด,"not-equal"
๋๋"time-out"
(timeout
๋งค๊ฐ๋ณ์๊ฐ0
์ธ ๊ฒฝ์ฐ์๋ง) ๋ฌธ์์ด์ผ ์ ์์ต๋๋ค.async
๊ฐtrue
์ด๋ฉด"ok"
๋๋"timed-out"
๋ฌธ์์ด ๊ฐ์ผ๋ก ์ดํ๋๋Promise
๊ฐ ๋ฉ๋๋ค. ํ๋ก๋ฏธ์ค๋ ์ ๋ ๊ฑฐ๋ถ๋์ง ์์ต๋๋ค.
์์
waitAsync() ์ฌ์ฉํ๊ธฐ
๊ณต์ ๋ Int32Array
์์
const sab = new SharedArrayBuffer(1024);
const int32 = new Int32Array(sab);
์ฝ๊ธฐ ์ค๋ ๋๊ฐ 0์ด ๋ ๊ฒ์ผ๋ก ์์๋๋ ์์น 0์์ ๋๊ธฐ ์ค์
๋๋ค. result.value
์ ํ๋ก๋ฏธ์ค์
๋๋ค.
const result = Atomics.waitAsync(int32, 0, 0, 1000);
// { async: true, value: Promise {<pending>} }
์ฝ๊ธฐ ์ค๋ ๋ ๋๋ ๋ค๋ฅธ ์ค๋ ๋์์ ๋ฉ๋ชจ๋ฆฌ ์์น 0์ด ํธ์ถ๋๊ณ ์ดํ ๊ฒฐ๊ณผ "ok"
๋ฌธ์์ด์ ํ์ธํ ์ ์์ต๋๋ค.
Atomics.notify(int32, 0);
// { async: true, value: Promise {<fulfilled>: 'ok'} }
"ok"
์ผ๋ก ํ์ธ๋์ง ์๋๋ค๋ฉด 2๊ฐ์ง ์์ธ์ด ์์ต๋๋ค. ์ฒซ ๋ฒ์งธ ์์ธ์ ๊ณต์ ๋ฉ๋ชจ๋ฆฌ ์์น์ ๊ฐ์ด ์์๊ณผ ๋ค๋ฅธ ๊ฒฝ์ฐ์ธ๋ฐ ์ด ๊ฒฝ์ฐ value
๋ ํ๋ก๋ฏธ์ค ๋์ "not-equal"
์ด ๋ ๋ฉ๋๋ค. ๋ ๋ฒ์งธ ์์ธ์ ์๊ฐ์ด ๋ง๋ฃ(ํ์์์)๋ ๊ฒฝ์ฐ๋ก ํ๋ก๋ฏธ์ค ๊ฒฐ๊ณผ๋ ๋ฌธ์์ด "time-out"
์
๋๋ค.
๋ช ์ธ์
Specification |
---|
ECMAScriptยฎ 2026 Language Specification # sec-atomics.waitasync |
๋ธ๋ผ์ฐ์ ํธํ์ฑ
Loadingโฆ