Fixed method signature of Atomics.waitAsync (#51602)

* Added method overloading for Atomics.waitAsync(Int32Array, number, number, number)

* fixed types

* fixed types

* fixed line ending

* CR fix

* Forgot the baseline
This commit is contained in:
Eyal Halpern Shalev 2022-12-02 02:41:28 +02:00 committed by GitHub
parent 1b75edcec6
commit 5435efbf37
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 104 additions and 20 deletions

View File

@ -2,6 +2,20 @@ interface Atomics {
/**
* A non-blocking, asynchronous version of wait which is usable on the main thread.
* Waits asynchronously on a shared memory location and returns a Promise
* @param typedArray A shared Int32Array or BigInt64Array.
* @param index The position in the typedArray to wait on.
* @param value The expected value to test.
* @param [timeout] The expected value to test.
*/
waitAsync(typedArray: BigInt64Array | Int32Array, index: number, value: bigint, timeout?: number): { async: false, value: "ok" | "not-equal" | "timed-out" } | { async: true, value: Promise<"ok" | "not-equal" | "timed-out"> };
waitAsync(typedArray: Int32Array, index: number, value: number, timeout?: number): { async: false, value: "not-equal" | "timed-out" } | { async: true, value: Promise<"ok" | "timed-out"> };
/**
* A non-blocking, asynchronous version of wait which is usable on the main thread.
* Waits asynchronously on a shared memory location and returns a Promise
* @param typedArray A shared Int32Array or BigInt64Array.
* @param index The position in the typedArray to wait on.
* @param value The expected value to test.
* @param [timeout] The expected value to test.
*/
waitAsync(typedArray: BigInt64Array, index: number, value: bigint, timeout?: number): { async: false, value: "not-equal" | "timed-out" } | { async: true, value: Promise<"ok" | "timed-out"> };
}

View File

@ -11,32 +11,60 @@ const int32 = new Int32Array(sab);
>Int32Array : Symbol(Int32Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2016.array.include.d.ts, --, --) ... and 1 more)
>sab : Symbol(sab, Decl(es2022SharedMemory.ts, 0, 5))
const sab64 = new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 1024);
>sab64 : Symbol(sab64, Decl(es2022SharedMemory.ts, 2, 5))
>SharedArrayBuffer : Symbol(SharedArrayBuffer, Decl(lib.es2017.sharedmemory.d.ts, --, --), Decl(lib.es2017.sharedmemory.d.ts, --, --))
>BigInt64Array.BYTES_PER_ELEMENT : Symbol(BigInt64ArrayConstructor.BYTES_PER_ELEMENT, Decl(lib.es2020.bigint.d.ts, --, --))
>BigInt64Array : Symbol(BigInt64Array, Decl(lib.es2020.bigint.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --), Decl(lib.es2022.array.d.ts, --, --))
>BYTES_PER_ELEMENT : Symbol(BigInt64ArrayConstructor.BYTES_PER_ELEMENT, Decl(lib.es2020.bigint.d.ts, --, --))
const int64 = new BigInt64Array(sab64);
>int64 : Symbol(int64, Decl(es2022SharedMemory.ts, 3, 5))
>BigInt64Array : Symbol(BigInt64Array, Decl(lib.es2020.bigint.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --), Decl(lib.es2022.array.d.ts, --, --))
>sab64 : Symbol(sab64, Decl(es2022SharedMemory.ts, 2, 5))
const waitValue = Atomics.wait(int32, 0, 0);
>waitValue : Symbol(waitValue, Decl(es2022SharedMemory.ts, 2, 5))
>waitValue : Symbol(waitValue, Decl(es2022SharedMemory.ts, 4, 5))
>Atomics.wait : Symbol(Atomics.wait, Decl(lib.es2017.sharedmemory.d.ts, --, --), Decl(lib.es2020.sharedmemory.d.ts, --, --))
>Atomics : Symbol(Atomics, Decl(lib.es2017.sharedmemory.d.ts, --, --), Decl(lib.es2017.sharedmemory.d.ts, --, --), Decl(lib.es2020.sharedmemory.d.ts, --, --), Decl(lib.es2022.sharedmemory.d.ts, --, --))
>wait : Symbol(Atomics.wait, Decl(lib.es2017.sharedmemory.d.ts, --, --), Decl(lib.es2020.sharedmemory.d.ts, --, --))
>int32 : Symbol(int32, Decl(es2022SharedMemory.ts, 1, 5))
const { async, value } = Atomics.waitAsync(int32, 0, BigInt(0));
>async : Symbol(async, Decl(es2022SharedMemory.ts, 3, 7))
>value : Symbol(value, Decl(es2022SharedMemory.ts, 3, 14))
>Atomics.waitAsync : Symbol(Atomics.waitAsync, Decl(lib.es2022.sharedmemory.d.ts, --, --))
const { async, value } = Atomics.waitAsync(int32, 0, 0);
>async : Symbol(async, Decl(es2022SharedMemory.ts, 5, 7))
>value : Symbol(value, Decl(es2022SharedMemory.ts, 5, 14))
>Atomics.waitAsync : Symbol(Atomics.waitAsync, Decl(lib.es2022.sharedmemory.d.ts, --, --), Decl(lib.es2022.sharedmemory.d.ts, --, --))
>Atomics : Symbol(Atomics, Decl(lib.es2017.sharedmemory.d.ts, --, --), Decl(lib.es2017.sharedmemory.d.ts, --, --), Decl(lib.es2020.sharedmemory.d.ts, --, --), Decl(lib.es2022.sharedmemory.d.ts, --, --))
>waitAsync : Symbol(Atomics.waitAsync, Decl(lib.es2022.sharedmemory.d.ts, --, --))
>waitAsync : Symbol(Atomics.waitAsync, Decl(lib.es2022.sharedmemory.d.ts, --, --), Decl(lib.es2022.sharedmemory.d.ts, --, --))
>int32 : Symbol(int32, Decl(es2022SharedMemory.ts, 1, 5))
const { async: async64, value: value64 } = Atomics.waitAsync(int64, 0, BigInt(0));
>async : Symbol(async, Decl(lib.es2022.sharedmemory.d.ts, --, --), Decl(lib.es2022.sharedmemory.d.ts, --, --))
>async64 : Symbol(async64, Decl(es2022SharedMemory.ts, 6, 7))
>value : Symbol(value, Decl(lib.es2022.sharedmemory.d.ts, --, --), Decl(lib.es2022.sharedmemory.d.ts, --, --))
>value64 : Symbol(value64, Decl(es2022SharedMemory.ts, 6, 23))
>Atomics.waitAsync : Symbol(Atomics.waitAsync, Decl(lib.es2022.sharedmemory.d.ts, --, --), Decl(lib.es2022.sharedmemory.d.ts, --, --))
>Atomics : Symbol(Atomics, Decl(lib.es2017.sharedmemory.d.ts, --, --), Decl(lib.es2017.sharedmemory.d.ts, --, --), Decl(lib.es2020.sharedmemory.d.ts, --, --), Decl(lib.es2022.sharedmemory.d.ts, --, --))
>waitAsync : Symbol(Atomics.waitAsync, Decl(lib.es2022.sharedmemory.d.ts, --, --), Decl(lib.es2022.sharedmemory.d.ts, --, --))
>int64 : Symbol(int64, Decl(es2022SharedMemory.ts, 3, 5))
>BigInt : Symbol(BigInt, Decl(lib.es2020.bigint.d.ts, --, --), Decl(lib.es2020.bigint.d.ts, --, --))
const main = async () => {
>main : Symbol(main, Decl(es2022SharedMemory.ts, 5, 5))
>main : Symbol(main, Decl(es2022SharedMemory.ts, 8, 5))
if (async) {
>async : Symbol(async, Decl(es2022SharedMemory.ts, 3, 7))
>async : Symbol(async, Decl(es2022SharedMemory.ts, 5, 7))
await value;
>value : Symbol(value, Decl(es2022SharedMemory.ts, 3, 14))
>value : Symbol(value, Decl(es2022SharedMemory.ts, 5, 14))
}
if (async64) {
>async64 : Symbol(async64, Decl(es2022SharedMemory.ts, 6, 7))
await value64;
>value64 : Symbol(value64, Decl(es2022SharedMemory.ts, 6, 23))
}
}
main();
>main : Symbol(main, Decl(es2022SharedMemory.ts, 5, 5))
>main : Symbol(main, Decl(es2022SharedMemory.ts, 8, 5))

View File

@ -15,6 +15,22 @@ const int32 = new Int32Array(sab);
>Int32Array : Int32ArrayConstructor
>sab : SharedArrayBuffer
const sab64 = new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 1024);
>sab64 : SharedArrayBuffer
>new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 1024) : SharedArrayBuffer
>SharedArrayBuffer : SharedArrayBufferConstructor
>BigInt64Array.BYTES_PER_ELEMENT * 1024 : number
>BigInt64Array.BYTES_PER_ELEMENT : number
>BigInt64Array : BigInt64ArrayConstructor
>BYTES_PER_ELEMENT : number
>1024 : 1024
const int64 = new BigInt64Array(sab64);
>int64 : BigInt64Array
>new BigInt64Array(sab64) : BigInt64Array
>BigInt64Array : BigInt64ArrayConstructor
>sab64 : SharedArrayBuffer
const waitValue = Atomics.wait(int32, 0, 0);
>waitValue : "ok" | "not-equal" | "timed-out"
>Atomics.wait(int32, 0, 0) : "ok" | "not-equal" | "timed-out"
@ -25,29 +41,49 @@ const waitValue = Atomics.wait(int32, 0, 0);
>0 : 0
>0 : 0
const { async, value } = Atomics.waitAsync(int32, 0, BigInt(0));
const { async, value } = Atomics.waitAsync(int32, 0, 0);
>async : boolean
>value : "ok" | "not-equal" | "timed-out" | Promise<"ok" | "not-equal" | "timed-out">
>Atomics.waitAsync(int32, 0, BigInt(0)) : { async: false; value: "ok" | "not-equal" | "timed-out"; } | { async: true; value: Promise<"ok" | "not-equal" | "timed-out">; }
>Atomics.waitAsync : (typedArray: Int32Array | BigInt64Array, index: number, value: bigint, timeout?: number | undefined) => { async: false; value: "ok" | "not-equal" | "timed-out"; } | { async: true; value: Promise<"ok" | "not-equal" | "timed-out">; }
>value : "not-equal" | "timed-out" | Promise<"ok" | "timed-out">
>Atomics.waitAsync(int32, 0, 0) : { async: false; value: "not-equal" | "timed-out"; } | { async: true; value: Promise<"ok" | "timed-out">; }
>Atomics.waitAsync : { (typedArray: Int32Array, index: number, value: number, timeout?: number | undefined): { async: false; value: "not-equal" | "timed-out"; } | { async: true; value: Promise<"ok" | "timed-out">; }; (typedArray: BigInt64Array, index: number, value: bigint, timeout?: number | undefined): { async: false; value: "not-equal" | "timed-out"; } | { async: true; value: Promise<"ok" | "timed-out">; }; }
>Atomics : Atomics
>waitAsync : (typedArray: Int32Array | BigInt64Array, index: number, value: bigint, timeout?: number | undefined) => { async: false; value: "ok" | "not-equal" | "timed-out"; } | { async: true; value: Promise<"ok" | "not-equal" | "timed-out">; }
>waitAsync : { (typedArray: Int32Array, index: number, value: number, timeout?: number | undefined): { async: false; value: "not-equal" | "timed-out"; } | { async: true; value: Promise<"ok" | "timed-out">; }; (typedArray: BigInt64Array, index: number, value: bigint, timeout?: number | undefined): { async: false; value: "not-equal" | "timed-out"; } | { async: true; value: Promise<"ok" | "timed-out">; }; }
>int32 : Int32Array
>0 : 0
>0 : 0
const { async: async64, value: value64 } = Atomics.waitAsync(int64, 0, BigInt(0));
>async : any
>async64 : boolean
>value : any
>value64 : "not-equal" | "timed-out" | Promise<"ok" | "timed-out">
>Atomics.waitAsync(int64, 0, BigInt(0)) : { async: false; value: "not-equal" | "timed-out"; } | { async: true; value: Promise<"ok" | "timed-out">; }
>Atomics.waitAsync : { (typedArray: Int32Array, index: number, value: number, timeout?: number | undefined): { async: false; value: "not-equal" | "timed-out"; } | { async: true; value: Promise<"ok" | "timed-out">; }; (typedArray: BigInt64Array, index: number, value: bigint, timeout?: number | undefined): { async: false; value: "not-equal" | "timed-out"; } | { async: true; value: Promise<"ok" | "timed-out">; }; }
>Atomics : Atomics
>waitAsync : { (typedArray: Int32Array, index: number, value: number, timeout?: number | undefined): { async: false; value: "not-equal" | "timed-out"; } | { async: true; value: Promise<"ok" | "timed-out">; }; (typedArray: BigInt64Array, index: number, value: bigint, timeout?: number | undefined): { async: false; value: "not-equal" | "timed-out"; } | { async: true; value: Promise<"ok" | "timed-out">; }; }
>int64 : BigInt64Array
>0 : 0
>BigInt(0) : bigint
>BigInt : BigIntConstructor
>0 : 0
const main = async () => {
>main : () => Promise<void>
>async () => { if (async) { await value; }} : () => Promise<void>
>async () => { if (async) { await value; } if (async64) { await value64; }} : () => Promise<void>
if (async) {
>async : boolean
await value;
>await value : "ok" | "not-equal" | "timed-out"
>value : Promise<"ok" | "not-equal" | "timed-out">
>await value : "ok" | "timed-out"
>value : Promise<"ok" | "timed-out">
}
if (async64) {
>async64 : boolean
await value64;
>await value64 : "ok" | "timed-out"
>value64 : Promise<"ok" | "timed-out">
}
}
main();

View File

@ -5,12 +5,18 @@
const sab = new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 1024);
const int32 = new Int32Array(sab);
const sab64 = new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 1024);
const int64 = new BigInt64Array(sab64);
const waitValue = Atomics.wait(int32, 0, 0);
const { async, value } = Atomics.waitAsync(int32, 0, BigInt(0));
const { async, value } = Atomics.waitAsync(int32, 0, 0);
const { async: async64, value: value64 } = Atomics.waitAsync(int64, 0, BigInt(0));
const main = async () => {
if (async) {
await value;
}
if (async64) {
await value64;
}
}
main();