can I await an array length to change to a specified value in JS.
for example:
Suppose there is a magic function named foo
here, and I can use foo
like this:
async funtion bar () {
let arr = [];
// Wait for the arr.length to change to 10, then invoke the handler
let result = await foo(arr, 10, handler);
return result;
}
I mean, when arr.length change to 1, 2, 3...6, 7, 8 or 9..., just wait in this line: let result = await foo(arr, 10, handler);
and do NOT return result
.
when arr.length change to 10, invoke the handler function, then return result
.
Does anyone know how to write this function foo
? or why can not write this function? Thanks
The really thing I want to know is:
We can use await
to wait for the result of some asynchronous operations like setInterval or AJAX, but what should I do if I want to wait for a specified value of a "set operation" (set operations: like set
in proxy
, or setter
in Object.defineProperty
).
and note that:
I want to know what should I do if I want to "await" a specified set operation., instead of just "watching" a specified set operation
For example keep waiting when arr.length is 0, 1, 2...9, and do something when arr.length is 10