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

196
Visualizações
Compiling object from time delayed emitted key-value pairs in javascript

I am receiving various key-value pairs from a eventemitter which need to be compiled into an object. Tricky part is that some of the needed key-values are time delayed. I am using a switch statment to write the values to temporary variables.

switch (
    data.keys
    case "key1_1":
      tempvalue1_1 = data.value;
     break;
    case "key1-2": 
      tempvalue1_2 = data.value;
     break;
    case "key1-3":
      tempvalue1_3 = data.value;
     break;
    case "key1-4":
      tempvalue1_4 = data.value;
     break;

as soon as data is being received I check using an if statment if the data is plausible (not null) and push it into my needed object

if (
 tempvalue1_1 &&
 tempvalue1_2 &&
 tempvalue1_3 &&
 tempvalue1_4
   ) {
 let object = {
 key1-1: "key1-1",
 key1-1_value: tempvalue1_1,
 key1-2: "key1-2",
 key1-2_value: tempvalue1_2,
 key1-3: "key1-3",
 key1-3_value: tempvalue1_3,
 key1-4: "key1-4",
 key1-4_value: tempvalue1_4,
  };
}

As soon as the object is compiled I send it off to elasticsearch afterwards I reset the key-values to null.

As stated before my problem is that some key-values are a bit time delayed. Which means key-value pair 1-1 and 1-2 always changes but key-value pair 1-3 and 1-4 does not always change as soon as key-value1-1 and 1-2 change and will be emitted up to 500ms after 1-1 and 1-2. I tried to use

setTimeout(function(){ },500)

within my above mentioned if statment but this does only makes the if statment true multiple times and builds the object with uncomplete data.

Any suggestions?

about 4 years ago · Juan Pablo Isaza
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