Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Sleep() {
- return new Promise(resolve => setTimeout(resolve, 10));
- }
- // introduces async getter and setter syntax
- class A {
- #a;
- constructor(a) {
- this.#a = a;
- }
- get async value() {
- await Sleep();
- return this.#a;
- }
- set async value(value) {
- await Sleep();
- this.#a = value;
- }
- }
- // New ~= syntax returns a promise for an async setter.
- async function G() {
- const a = new A(1);
- const b = new A(2);
- const bValue = await b.value;
- const aValue = await a.value;
- await a.value ~= bValue;
- await b.value ~= aValue;
- }
- // Destructuring syntax if the left is an array or object
- // ~= returns an array of promises
- async function G() {
- const a = new A(1);
- const b = new A(2);
- await.all [a.value, b.value] ~= [await b.value, await a.value];
- }
- // What about for object destructuring? Unsure.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement