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

116
Visualizações
Run sagas in sequence

I am trying to write some code that will execute several blocking sagas in sequence. For my use case, saga1 must complete before saga2 can start executing. Here is some code that shows a simplified version of what I am trying to do:

function* logger() {
  console.log('spy 1');
}

function* logger2() {
  console.log('spy2');
}

function* spy1() {
  yield takeEvery('*', logger);
}

function* spy2() {
  yield takeEvery('*', logger2);
}

export default function* rootSaga() {
  yield call(spy1);
  yield call(spy2);
}

When I dispatch an action, I only ever reach the first console.log. I know that if I use fork() instead of call() I can get both to run, however I do not want them to run in parallel. How can I make my first logger function complete and allow saga to move on to the second.

Thanks!

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

0

What about creating a single watcher that simulates what takeEvery does but in a sequencial manner?

function* logger() {
  yield delay(1000);
  console.log("logger 1");
}

function* logger2() {
  console.log("logger 2");
}

function* watcher() {
  while (yield take("*")) {
    yield call(logger);
    yield call(logger2);
  }
}

function* rootSaga() {
  yield call(watcher);
}

One of the points I'd like to bring here is that, first is that takeEvery uses a fork internally and then according to takeEvery's documentation:

There is no guarantee that the tasks will terminate in the same order they were started

so maybe using takeEvery won't accomplish what you need.

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