Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

246
Views
Zone.js is not expire per request in node and it's value exists in stack

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

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I didn't ever use zone.js. But I think it is because of express doesn't create a new thread for each request and zone.js keeps values for a thread. I found another question about nodejs thread logic and this might be what you are looking for. If you want empte ttlStore per request, I can suggest you to add a middleware that runs end of the request and clear your storage.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!