Skip to content

Instantly share code, notes, and snippets.

@SyedTayyabUlMazhar
Created September 4, 2022 07:15
Show Gist options
  • Save SyedTayyabUlMazhar/84534369bbde885fb5bd8a03a5890b28 to your computer and use it in GitHub Desktop.
Save SyedTayyabUlMazhar/84534369bbde885fb5bd8a03a5890b28 to your computer and use it in GitHub Desktop.
const takeLatest = (patternOrChannel, saga, ...args) => fork(function* ()
{
let lastTask
while (true)
{
const action = yield take(patternOrChannel)
if (lastTask)
{
yield cancel(lastTask) // cancel is no-op if the task has already terminated
}
lastTask = yield fork(saga, ...args.concat(action))
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment