Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

176
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda