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

118
Views
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 answers
Answer question

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 Report
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!