Created
September 4, 2022 07:15
-
-
Save SyedTayyabUlMazhar/84534369bbde885fb5bd8a03a5890b28 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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