@todojs/

11.-generadora

JavaScript

No description

fork
loading

This Plugin Crashed!

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

function asyncSqrt(value, callback) {
    console.log('START execution with value =', value);
    setTimeout(function() {
        callback(value, value * value);
    }, 0 | Math.random() * 100);
}

function* gen(callback) {
    for (var i = 0; i < 10; i++) {
        yield asyncSqrt(i, callback);
    }
}
var iterator = gen(function (value, result) {
    console.log('END execution with value =', value, 'and result =', result);
    iterator.next();
});
iterator.next(); 
Native Browser JavaScript