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

183
Visualizações
forkJoin but next observable depends on the one before

https://www.learnrxjs.io/learn-rxjs/operators/combination/forkjoin

const example = forkJoin({
  // emit 'Hello' immediately
  sourceOne: of('Hello'),
  // emit 'World' after 1 second
  sourceTwo: of('World').pipe(delay(1000)),
  // throw error
  sourceThree: throwError('This will error')
}).pipe(catchError(error => of(error)));

// output: 'This will Error'
const subscribe = example.subscribe(val => console.log(val));

That's the main implementation but in my case, to call sourceTwo I need to use the data from sourceOne and the same with sourceThree. All calls need the previous observable in order to fetch data.

I only care about final result, don't need to merge anything, just do what this example does, show what sourceThree returns

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

forkJoin is intended to run calls in parallel, like Promise.all(). In your case, you cannot do that since the calls depend on each other.

Instead, you can pipe them. If you can parallelize 2 and 3, you can do something like the following.

sourceOne.pipe(
  res => forkJoin(makeCall2(res), makeCall3(res))
)

To complete the Promise comparison:

makeCall().then(res => Promise.all([
    makeCall2(res),
    makeCall3(res)
]));
about 4 years ago · Juan Pablo Isaza Relatório
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