Using Atomics.waitAsync
in js code compiled by Closure compiler was giving an error.
// source.js
function b(a) {
return Atomics.waitAsync(a, 1, 2);
}
b(new Int32Array(10));
# compile command
> java -jar node_modules/google-closure-compiler-java/compiler.jar --js source.js --compilation_level ADVANCED
source.js:2:17: WARNING - [JSC_INEXISTENT_PROPERTY] Property waitAsync never defined on Atomics
2| return Atomics.waitAsync(a, 1, 2);
^^^^^^^^^
0 error(s), 1 warning(s), 72.7% typed
var a=new Int32Array(10);Atomics.g(a,1,2);
There are two issues here
waitAsync
method is renamed to g
By adding an extern file Async.js
to the compilation both problems are resolved
// Async.js
/** @externs */
/**
* @param {Int32Array|BigInt64Array} typedArray
* @param {number} index
* @param {number} value
* @param {number=} timeout
* return {!{async: boolean, value: string|!Promise<!string>}}
*/
Atomics.waitAsync = function(typedArray, index, value, timeout){};
# compile with extern file
❯ java -jar node_modules/google-closure-compiler-java/compiler.jar --js source.js Atomics.js --compilation_level ADVANCED
var a=new Int32Array(10);Atomics.waitAsync(a,1,2);