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

250
Visualizações
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
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