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

195
Views
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
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!