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

173
Views
Function execution queue based on parameters

I'm struggling to find a solution for this problem. The use case is as follow:

  • I have a function to retrieve a resource from an external location
  • Quite often the call to this function n number of times concurrently
  • When this happen I would like all the function call to "wait" until the first function returns and just use the output of that function
  • The crux of the issue here that the function is called 10 times a the same time

Say for example the function is:

function retrieveResource(resourceId, callback) {
  extLib.getResource(resourceId, function (err, data) {
    callback(err, data);  
  };
};

So when multiple "caller" are calling retrieveResource functions, often they have the same resourceId. When this happen within say 1 second interval, I just want to have 1 call to extLib.getResource executed and the rest will just use the same value as the first function call.

Using cache doesn't quite work out here because the function is called roughly at the same time, they all check the cache roughly at the same time and the cache is empty at that point.

I looked at _.debounce, _.throttle and they are not what I'm looking for since debounce is executing just one function and throttle is still executing all functions.

Any ideas?

over 4 years ago · Santiago Trujillo
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!