1

I’m in a need to do a certain algorithm but I'm having a problem with For loops. The first problem is that I can't make the execution of two For loops (one inside the other) without the first ends and doesn't wait for the second one to finish

for(i = ports_default; i <= ports_final; i++) {
        for(j=ports_default; j<= (ports_default + num_ports) ;j++){
            client.portUnmapping({public: j},function (err){
                if (err) {
                    callback(err);
                }
                else {          
                    console.log('Port ' + ports_default + ' unmapped');
                    ports_default= ports_default + 1;
                    if(ports_default == j) {
                        callback();
                    }
                }
            });                 
        }
        ports_default = ports_default + num_ports + 1;
}

I've tried the async module but couldn't find a proper solution for this problem, the second problem is that node won't wait for a response from the portUnmapping function, my question is if theres a way to atleast force it somehow to wait for both For loops to end (in the proper order not finishing the first one and then the second one).

1 Answer 1

2

you can try use nimble library http://caolan.github.io/nimble/

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.