question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

race effect without automatic cancellation ?

See original GitHub issue

Hi,

I have this use case where I want to hava a race but avoid automatic cancellation :

export function* mySaga() {
  const task = yield fork(myApiCallSaga)
  let { timeout, result } = yield race({
    timeout: delay(500),
    result: task.done
  })

  if (timeout) {
    yield put({ type: 'display-something' })
    result = yield join(task)
  }

  return result
}

Basically here, I trigger an Api call in a forked saga, and if the forked task lasts more than 500ms, I display something (trigger a put), and join the forked tasked to get the result.

The problem here is that the race effect cancels myApiCall if the timeout expires.

May be there’s another way of doing this.

Thanks a lot

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:1
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
youknowriadcommented, Mar 10, 2016

I’ve found this workaround, make the promise uncancelable :

export function* mySaga() {
  const task = yield fork(myApiCallSaga)
  const taskPromise = new Promise((resolve, reject) => {
    task.done.then(resolve, reject)
  })
  let { timeout, result } = yield race({
    timeout: delay(500),
    result: taskPromise
  })

  if (timeout) {
    yield put({ type: 'display-something' })
    result = yield taskPromise
  }

  return result
}

What do you think ?

1reaction
lnunnocommented, Aug 6, 2020

@yelouafi You mentioned here and a couple other issues that you were thinking of adding a non destructive race effect, can I ask if you tried this or have plans to implement? I have a use case for that type of effect as well.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Racing Effects | Redux-Saga
In the case a CANCEL_TASK action is dispatched, the race Effect will automatically cancel backgroundTask by throwing a cancellation error inside it.
Read more >
A Meta-Analysis of the “Erasing Race” Effect in the United ...
The “erasing race” effect is the reduction of the salience of “race” as an alliance cue when recalling coalition membership, once more accurate ......
Read more >
Americans and 'Cancel Culture': Where Some See Calls for ...
“[Cancel culture] means rewriting history and stopping the acknowledgment of facts because they are offensive to a racial, religious, ...
Read more >
Automation and the future of the African American workforce
Even without the effects of automation, this distribution exacerbates racial wealth inequality. For example, support roles are predicted to ...
Read more >
What is a Race Condition? - TechTarget
Learn what race conditions are in computer science and programming, ... A noncritical race condition does not directly affect the end state of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found