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

249
Views
How to handle multiple async operations using promises?

I have some code with 2 functions. taskA requires some value and gets that value via a callback that returns the value inside a promise. It then returns the result of doing something with that value via a second callback. taskB provides the value via a callback that is also passed as a parameter, but this callback is synchronous.

How can I get the value from taskB and pass it to taskA, and get the result to pass it back to taskB? I can modify taskA, but taskB must provide its value and obtain a result via a synchronous callback.

async function taskA(requestValue: () => Promise<Value>, provideResult: (result: Result) => void) {
  while(someCondition) {
    let value: Value = await requestValue();
    let result: Result = processValue(value);
    provideResult(result);
  }
}

function taskB(valueCallback: (value: Value) => Result) {
  let state: State = someState;
  ...
  let handleEvent = (event) => {
    let result: Result = valueCallback(convertToValue(event));
    state = updateState(result);
  }
}

Here's a sequence diagram of the behaviour I want to enable: sequence diagram

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!