Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const ee = new (require("events")).EventEmitter();
- const array = Array(1000).fill(0);
- const delay = ms => new Promise(r => setTimeout(r, ms));
- function funzioneAsincrona() {
- return new Promise(async (resolve, reject) => {
- ee.on("mioEvento", reject);
- for (let i = 0; i < array.length; i++) {
- // simula XHR
- await delay(100);
- console.log("op", i);
- }
- });
- }
- setTimeout(() => ee.emit("mioEvento"), 2000);
- (async function run() {
- try {
- await funzioneAsincrona();
- } catch (err) {
- console.log("<<<<<< error");
- }
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement