@todojs/

12.-generadora-callback

JavaScript

No description

fork
loading

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.6848027186724976","path":"main.js","file":{"path":"main.js","content":{"asEncoding":{"base64":"InVzZSBzdHJpY3QiOw0KDQpmdW5jdGlvbiBhc3luY1NxcnQodmFsdWUsIGNhbGxiYWNrKSB7DQogICAgY29uc29sZS5sb2coJ1NUQVJUIGV4ZWN1dGlvbiB3aXRoIHZhbHVlID0nLCB2YWx1ZSk7DQogICAgc2V0VGltZW91dChmdW5jdGlvbigpIHsNCiAgICAgICAgY2FsbGJhY2sodmFsdWUsIHZhbHVlICogdmFsdWUpOw0KICAgIH0sIDAgfCBNYXRoLnJhbmRvbSgpICogMTAwKTsNCn0NCg0KZnVuY3Rpb24qIGdlbihjYWxsYmFjaykgew0KICAgIHZhciBhcnIgPSBbMCwxLDIsMyw0LDUsNiw3LDgsOV07DQogICAgYXJyLmZvckVhY2goZnVuY3Rpb24gKGkpIHsNCiAgICAgICAgeWllbGQgYXN5bmNTcXJ0KGksIGNhbGxiYWNrKTsNCiAgICB9KTsNCn0NCnZhciBpdGVyYXRvciA9IGdlbihmdW5jdGlvbiAodmFsdWUsIHJlc3VsdCkgew0KICAgIGNvbnNvbGUubG9nKCdFTkQgZXhlY3V0aW9uIHdpdGggdmFsdWUgPScsIHZhbHVlLCAnYW5kIHJlc3VsdCA9JywgcmVzdWx0KTsNCiAgICBpdGVyYXRvci5uZXh0KCk7DQp9KTsNCml0ZXJhdG9yLm5leHQoKTs="},"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) {
    var arr = [0,1,2,3,4,5,6,7,8,9];
    arr.forEach(function (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