I am very new to express.js ,node.js . In our application, we are using the zone.js library to store the ttl value in the stack. As per my understanding the zone is only applicable to per request once the response is sent to end user. After that zone will die.
But what happen in my case, it will still exists. For an example:
In first request i have store ttl value to 150 using storeTtl function. and later while sending the response i tried to get the value using getMinimumTtlVal function. In response i am getting 150, that is correct because stack has only one value present and before calling the send api request, it should need to be empty but that is not happening.
When i made a another request with ttl value 180 and store ttl using storeTtl function but when i tried to get the value in getMinimumTtlVal function, now the satck has two value (150,180). Because of the min function, it is returning 150.
Min function is required here, because in some request we call the storeTtl function couple of times. I am not able to figure out, what is wrong in this code.
The sample code is below :
require('zone.js/dist/zone-node.js');
class TtlStore {
storeTtl (ttl) {
if (!Zone.current.ttlStore) {
Zone.current.ttlStore = [];
}
Zone.current.ttlStore.push(ttl);
}
getMinimumTtlVal () {
const minValue = Math.min(...Zone.current.ttlStore);
if (isNaN(minValue) || !Number.isInteger(minValue)) {
return 0;
}
return minValue;
}
}
module.exports = TtlStore;
Thanks in advance