Like a Promise, await
will call any .then()
function on its operand. This can be used to create values that change every time they are await
ed.
let lastId = 1;
const id = {
then(fn, errfn) {
fn(lastId++);
}
};
async function foo() {
console.log(await id); // 1
console.log(await id); // 2
}
Can you do something like this:
?