Skip to content

Instantly share code, notes, and snippets.

@emadb emadb/gist:5525652
Last active Dec 17, 2015

Embed
What would you like to do?
Come cacchio funziona!! Perchè complete non viene mai eseguito??
var async = require('async');
var functions = [];
functions.push(function(){ console.log("1"); return test1(1); });
functions.push(function(){ console.log("2"); return test1(2); });
functions.push(function(){ console.log("3"); return test1(3); });
async.parallel(functions, function(err, result){
console.log('complete', result);
});
function test1 (value){
return "hello " + value;
}
@unlucio

This comment has been minimized.

Copy link

unlucio commented May 6, 2013

prova cosi':

var _ = require('underscore')
var functions = [];

function test1(value) {
    return "hello " + value;
}
functions.push(function() {
    console.log("1");
    return test1(1);
});
functions.push(function() {
    console.log("2");
    return test1(2);
});
functions.push(function() {
    console.log("3");
    return test1(3);
});


for (var fnIndex in functions) {
    var selectedFunction = functions[fnIndex];

    (function(subjectFunction, index) {
        subjectFunction();

        functions[index] = false;

        var allListChanged = _.every(functions, function(value, key) {
            return (value === false);
        });

        if (allListChanged) {
            console.log("finito");
        }

    }(selectedFunction, fnIndex));
}

ti manchera' una graffa, come minimo

@fakemau5

This comment has been minimized.

Copy link

fakemau5 commented May 6, 2013

my 2c: passa la callback che va invocata dalle tue funzioni parallele:

var async = require('async');
var functions = [];

functions.push(function(callback){ setTimeout( function(){console.log("1"); callback(null,test1(1));}, 500 )});
functions.push(function(callback){ console.log("2"); callback(null,test1(2)); });
functions.push(function(callback){ console.log("3"); callback(null,test1(3)); });

async.parallel(functions, function(err, result){
    console.log('complete', result);
});

function test1 (value){
    return "hello " + value;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.