-
Notifications
You must be signed in to change notification settings - Fork 0
resetDeduper()
Amphiluke edited this page Nov 30, 2025
·
2 revisions
The function resetDeduper() brings a deduper to the initial state by clearing currently active dedupe lock. For most cases, there are appropriate methods of lock removal, such as limiting the maximum allowed process duration (see createTimekeeper()). But if you find yourself in that rare situation where you need to remove the lock without aborting currently pending process, resetDeduper() may be helpful.
In the simplest case, resetDeduper() expects a deduper reference as a single argument. This reverts the deduper state as a whole. If you use key-based deduplication, you may provide a distinct key as the second (optional) argument to perform a selective dedupe lock removal.
import {createDeduper, resetDeduper} from 'async-aid';
const getUsersWithRole = createDeduper(async (role) => {
const response = await fetch(`/user-api/users?role=${role}`);
return await response.json();
}, {
keyFn: (role) => role,
});
// ...
resetDeduper(getUsersWithRole, 'tester'); // remove dedupe lock for a specific key
resetDeduper(getUsersWithRole); // reset the deduper state entirely