main.js
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