@todojs/

7.-promiseSqrt

JavaScript

No description

fork
loading

This Plugin Crashed!

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

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

promiseSqrt(2).then(function(obj) {
    console.log('END execution with value =', obj.value, 'and result =', obj.result);
});
console.log('COMPLETED ?');
Native Browser JavaScript