From 43dc14047c015e2b4834c760ff28f15fb7675b35 Mon Sep 17 00:00:00 2001 From: Jongha Kim Date: Fri, 16 Jun 2023 23:50:19 +0900 Subject: [PATCH] =?UTF-8?q?[ko]=20JavaScript:=20TypedArray.subarray()=20?= =?UTF-8?q?=EC=99=B8=201=EA=B0=9C=20=EC=B6=94=EA=B0=80=20(#13100)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global_objects/atomics/waitasync/index.md | 83 +++++++++++++++++++ .../typedarray/subarray/index.md | 71 ++++++++++++++++ 2 files changed, 154 insertions(+) create mode 100644 files/ko/web/javascript/reference/global_objects/atomics/waitasync/index.md create mode 100644 files/ko/web/javascript/reference/global_objects/typedarray/subarray/index.md diff --git a/files/ko/web/javascript/reference/global_objects/atomics/waitasync/index.md b/files/ko/web/javascript/reference/global_objects/atomics/waitasync/index.md new file mode 100644 index 00000000000000..b3a59719028c0d --- /dev/null +++ b/files/ko/web/javascript/reference/global_objects/atomics/waitasync/index.md @@ -0,0 +1,83 @@ +--- +title: Atomics.waitAsync() +slug: Web/JavaScript/Reference/Global_Objects/Atomics/waitAsync +l10n: + sourceCommit: 194d3e00cb93a6e5ea44812548f4131cb17f0381 +--- + +{{JSRef}} + +**`Atomics.waitAsync()`** 정적 메서드는 공유 메모리 위치에서 비동기적으로 대기하고 {{jsxref("Promise")}}를 반환합니다. + +{{jsxref("Atomics.wait()")}}와는 다르게, `waitAsync`는 논 블록킹이며 메인 스레드에서 사용할 수 있습니다. + +> **참고:** 이 작업은 오직 공유된 {{jsxref("Int32Array")}} 혹은 {{jsxref("BigInt64Array")}}에서만 동작합니다. + +## 구문 + +```js-nolint +Atomics.waitAsync(typedArray, index, value) +Atomics.waitAsync(typedArray, index, value, timeout) +``` + +### 매개변수 + +- `typedArray` + - : 공유된 {{jsxref("Int32Array")}} 혹은 {{jsxref("BigInt64Array")}}. +- `index` + - : `typedArray`에서의 대기하고 있는 인덱스. +- `value` + - : 테스트할 기대값. +- `timeout` {{optional_inline}} + - : 대기 시간(밀리초). 시간이 명시되지 않으면 {{jsxref("Infinity")}}입니다. + +### 반환 값 + +다음 속성을 가진 {{jsxref("Object")}}. + +- `async` + - `value` 속성이 {{jsxref("Promise")}}인지 아닌지를 나타내는 부울입니다. +- `value` + - `async`가 `false`이면, `"not-equal"` 또는 `"time-out"`(`timeout` 매개변수가 `0`인 경우에만) 문자열일 수 있습니다. + `async`가 `true`이면 `"ok"` 또는 `"timed-out"` 문자열 값으로 이행되는 {{jsxref("Promise")}}가 됩니다. 프로미스는 절대 거부되지 않습니다. + +## 예제 + +### waitAsync() 사용하기 + +공유된 `Int32Array`에서 + +```js +const sab = new SharedArrayBuffer(1024); +const int32 = new Int32Array(sab); +``` + +읽기 스레드가 0이 될 것으로 예상되는 위치 0에서 대기 중입니다. `result.value`은 프로미스입니다. + +```js +const result = Atomics.waitAsync(int32, 0, 0, 1000); +// { async: true, value: Promise {} } +``` + +읽기 스레드 또는 다른 스레드에서 메모리 위치 0이 호출되고 이행 결과 `"ok"` 문자열을 확인할 수 있습니다. + +```js +Atomics.notify(int32, 0); +// { async: true, value: Promise {: 'ok'} } +``` + +`"ok"`으로 확인되지 않는다면 2가지 원인이 있습니다. 첫 번째 원인은 공유 메모리 위치의 값이 예상과 다른 경우인데 이 경우 `value`는 프로미스 대신 `"not-equal"`이 될 됩니다. 두 번째 원인은 시간이 만료(타임아웃)될 경우로 프로미스 결과는 문자열 `"time-out"`입니다. + +## 명세서 + +{{Specifications}} + +## 브라우저 호환성 + +{{Compat}} + +## 같이 보기 + +- {{jsxref("Atomics")}} +- {{jsxref("Atomics.wait()")}} +- {{jsxref("Atomics.notify()")}} diff --git a/files/ko/web/javascript/reference/global_objects/typedarray/subarray/index.md b/files/ko/web/javascript/reference/global_objects/typedarray/subarray/index.md new file mode 100644 index 00000000000000..cd41928fc1cce8 --- /dev/null +++ b/files/ko/web/javascript/reference/global_objects/typedarray/subarray/index.md @@ -0,0 +1,71 @@ +--- +title: TypedArray.prototype.subarray() +slug: Web/JavaScript/Reference/Global_Objects/TypedArray/subarray +l10n: + sourceCommit: 7b35a48ac0a10b67f9bd5270b082d40deff9c953 +--- + +{{JSRef}} + +**`subarray()`** 메서드는 이 TypedArray 객체와 동일한 {{jsxref("ArrayBuffer")}} 저장소에 동일한 요소의 타입을 가진 새로운 TypedArray를 반환합니다. 시작 오프셋은 **포함**하고 마지막 오프셋은 **제외**합니다. TypedArray는 [타입이 지정된 배열 유형](/ko/docs/Web/JavaScript/Reference/Global_Objects/TypedArray#typedarray_objects) 중 하나입니다. + +{{EmbedInteractiveExample("pages/js/typedarray-subarray.html")}} + +## 구문 + +```js-nolint +subarray() +subarray(begin) +subarray(begin, end) +``` + +### 매개변수 + +- `begin` {{optional_inline}} + - : 시작할 요소입니다. 오프셋 값은 포함되어 있습니다. 이 값을 명시하지 않으면 배열 전체가 새로운 뷰에 포함됩니다. +- `end` {{optional_inline}} + - : 마지막 요소입니다. 오프셋 값은 제외합니다. 이 값을 명시하지 않으면 `begin`에 지정된 요소부터 배열 끝까지 + 모든 요소가 새로운 뷰에 포함됩니다. + +### 반환 값 + +새로운 {{jsxref("TypedArray")}} 객체. + +## 설명 + +`begin`과 `end`으로 명시된 범위는 현재 배열의 유효한 인덱스 범위로 고정됩니다. 새 배열의 계산된 길이가 음수인 경우 +0으로 고정됩니다. `begin` 또는 `end`가 음수인 경우 배열의 시작이 아닌 끝의 인덱스를 참조합니다. + +또한 명심하셔야 할 점은 기존 버퍼에 새로운 뷰(view)를 생성하는 것뿐입니다. +새 객체의 내용을 변경하면 원래 객체에 영향을 미치며 그 반대의 경우도 마찬가지입니다. + +## 예제 + +### subarray() 메서드 사용하기 + +```js +const buffer = new ArrayBuffer(8); +const uint8 = new Uint8Array(buffer); +uint8.set([1, 2, 3]); + +console.log(uint8); // Uint8Array [ 1, 2, 3, 0, 0, 0, 0, 0 ] + +const sub = uint8.subarray(0, 4); + +console.log(sub); // Uint8Array [ 1, 2, 3, 0 ] +``` + +## 명세서 + +{{Specifications}} + +## 브라우저 호환성 + +{{Compat}} + +## 같이 보기 + +- [Polyfill of `TypedArray.prototype.subarray` in `core-js`](https://github.com/zloirock/core-js#ecmascript-typed-arrays) +- [JavaScript 형식화 배열](/ko/docs/Web/JavaScript/Guide/Typed_arrays) +- {{jsxref("TypedArray")}} +- {{jsxref("ArrayBuffer")}}