@todojs/

17.-async-await

ES6

No description

fork
loading

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.4721072683256238","path":"main.js","file":{"path":"main.js","content":{"asEncoding":{"base64":"InVzZSBzdHJpY3QiOw0KDQpmdW5jdGlvbiBwcm9taXNlU3FydCh2YWx1ZSl7DQogICAgcmV0dXJuIG5ldyBQcm9taXNlKGZ1bmN0aW9uIChmdWxmaWxsLCByZWplY3Qpew0KICAgICAgICBjb25zb2xlLmxvZygnU1RBUlQgZXhlY3V0aW9uIHdpdGggdmFsdWUgPScsIHZhbHVlKTsNCiAgICAgICAgc2V0VGltZW91dChmdW5jdGlvbigpIHsNCiAgICAgICAgICAgIGZ1bGZpbGwoeyB2YWx1ZTogdmFsdWUsIHJlc3VsdDogdmFsdWUgKiB2YWx1ZSB9KTsNCiAgICAgICAgfSwgMCB8IE1hdGgucmFuZG9tKCkgKiAxMDApOw0KICAgIH0pOw0KfQ0KDQphc3luYyBmdW5jdGlvbiBydW4oKSB7DQogICAgZm9yICh2YXIgbiA9IDA7IG4gPD0gOTsgbisrKSB7DQogICAgICAgIHZhciBvYmogPSBhd2FpdCBwcm9taXNlU3FydChuKTsNCiAgICAgICAgY29uc29sZS5sb2coJ0VORCBleGVjdXRpb24gd2l0aCB2YWx1ZSA9Jywgb2JqLnZhbHVlLCAnYW5kIHJlc3VsdCA9Jywgb2JqLnJlc3VsdCk7DQogICAgfQ0KfQ0KcnVuKCk7IA=="},"asBuffer":null},"loaded":true}}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
"use strict";

function promiseSqrt(value){
    return new Promise(function (fulfill, reject){
        console.log('START execution with value =', value);
        setTimeout(function() {
            fulfill({ value: value, result: value * value });
        }, 0 | Math.random() * 100);
    });
}

async function run() {
    for (var n = 0; n <= 9; n++) {
        var obj = await promiseSqrt(n);
        console.log('END execution with value =', obj.value, 'and result =', obj.result);
    }
}
run(); 
Babel Compiler v6.4.4 Copyright (c) 2014-2015 Sebastian McKenzie