Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2023
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function Sleep() {
  2.     return new Promise(resolve => setTimeout(resolve, 10));
  3. }
  4.  
  5. // introduces async getter and setter syntax
  6. class A {
  7.     #a;
  8.     constructor(a) {
  9.         this.#a = a;
  10.     }
  11.     get async value() {
  12.         await Sleep();
  13.         return this.#a;
  14.     }
  15.     set async value(value) {
  16.         await Sleep();
  17.         this.#a = value;
  18.     }
  19. }
  20.  
  21. // New ~= syntax returns a promise for an async setter.
  22.  
  23. async function G() {
  24.     const a = new A(1);
  25.     const b = new A(2);
  26.     const bValue = await b.value;
  27.     const aValue = await a.value;
  28.     await a.value ~= bValue;
  29.     await b.value ~= aValue;
  30. }
  31.  
  32. // Destructuring syntax if the left is an array or object
  33. // ~= returns an array of promises
  34. async function G() {
  35.     const a = new A(1);
  36.     const b = new A(2);
  37.     await.all [a.value, b.value] ~= [await b.value, await a.value];
  38. }
  39.  
  40. // What about for object destructuring? Unsure.
  41.  
  42.  
  43.  
  44.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement