@anonymous/

AmusingZealousEnvironment

JavaScript

No description

fork
loading

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.2716094186715634","path":"main.js","file":{"path":"main.js","content":{"asEncoding":{"base64":"YXN5bmMgZnVuY3Rpb24gZG91YmxlQW5kQWRkMShhLCBiKSB7CiAgYSA9IGF3YWl0IGRvdWJsZUFmdGVyMVNlYyhhKTsKICBiID0gYXdhaXQgZG91YmxlQWZ0ZXIxU2VjKGIpOwogIHJldHVybiBhICsgYjsKfQoKYXN5bmMgZnVuY3Rpb24gZG91YmxlQW5kQWRkMihhLCBiKSB7CiAgYSA9IGRvdWJsZUFmdGVyMVNlYyhhKTsKICBiID0gZG91YmxlQWZ0ZXIxU2VjKGIpOwogIHJldHVybiBhd2FpdCBhICsgYXdhaXQgYjsKfQoKZnVuY3Rpb24gZG91YmxlQWZ0ZXIxU2VjKHBhcmFtKSB7CiAgcmV0dXJuIG5ldyBQcm9taXNlKHJlc29sdmUgPT4gewogICAgc2V0VGltZW91dCgoKSA9PiByZXNvbHZlKHBhcmFtICogMiksIDEwMDApOwogIH0pOwp9Cgpjb25zb2xlLnRpbWUoInRpbWVyMSIpOwpkb3VibGVBbmRBZGQxKDEsIDIpLnRoZW4ocmVzdWx0ID0+IHsKICBjb25zb2xlLmxvZyhyZXN1bHQpOwogIGNvbnNvbGUudGltZUVuZCgidGltZXIxIikKfSk7Cgpjb25zb2xlLnRpbWUoInRpbWVyMiIpOwpkb3VibGVBbmRBZGQyKDEsIDIpLnRoZW4ocmVzdWx0ID0+IHsKICBjb25zb2xlLmxvZyhyZXN1bHQpOwogIGNvbnNvbGUudGltZUVuZCgidGltZXIyIikKfSk7"},"asBuffer":null},"loaded":true}}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
async function doubleAndAdd1(a, b) {
  a = await doubleAfter1Sec(a);
  b = await doubleAfter1Sec(b);
  return a + b;
}

async function doubleAndAdd2(a, b) {
  a = doubleAfter1Sec(a);
  b = doubleAfter1Sec(b);
  return await a + await b;
}

function doubleAfter1Sec(param) {
  return new Promise(resolve => {
    setTimeout(() => resolve(param * 2), 1000);
  });
}

console.time("timer1");
doubleAndAdd1(1, 2).then(result => {
  console.log(result);
  console.timeEnd("timer1")
});

console.time("timer2");
doubleAndAdd2(1, 2).then(result => {
  console.log(result);
  console.timeEnd("timer2")
});
Native Browser JavaScript