sorry the topic might be confusing coz i don't know how to say that.
consider a situation that i have a async function with one parameter. an array.
i used this parameter inside function. I'm afraid that calling function multiple times could rewrite the array i sent to function previously. Could it be happened?
assume this code: //this is an IPC function which will be called by another process.
responder.on('message', function(request) {
resp = msgpack.unpack(request);
//resp is my array.
myvar = resp[1];
.
.
.
}
I'm afraid resp[] will be overwrite before the first call finished and this cause problem in first call code execution.
Consider the following example:
function doStuff() {
var temp = 0;
function modifyTemp(temp) {
temp = 5;
}
modifyTemp(temp);
//the value of temp is still 0
function modifyTemp2() {
temp = 10;
}
modifyTemp2();
//temp now equals 10
}
doStuff();
Notice that temp is within the closure scope of "doStuff()". So any reference to temp within this scope will use this reference, unless there is one that takes precedence, as in the example of modifyTemp(temp) declaration. In this case, a temp copy of the temp variable is created and stored to "temp" which is modifed within the scope of only this funciton, and the temp defined within the closure is left untouched. So the answer to your question is, it depends on what level of scope you have declared your resp variabled. The way your could looks to be written, I would suggest that what you are concnered about happening is in fact a concern.
The following modifications (provided in commented/uncommented lines) would potentially provide jurastically different behaviors, depending on how the rest of your program function, and how much async stuff you have going on. Notice that the uncommented implementation redefines the variable, so that we don't need to worry about consecutive runs or other functions interfering with it's value.
responder.on('message', function(request) {
//resp = msgpack.unpack(request);
var resp = msgpack.unpack(request);
//resp is my array.
myvar = resp[1];
.
.
.
}