Skip to content

Commit

Permalink
feat(plugin-history-sync): add listen option (#418)
Browse files Browse the repository at this point in the history
  • Loading branch information
orionmiz authored Oct 20, 2023
1 parent b5f6a3c commit 2a24b38
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions extensions/plugin-history-sync/src/queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,22 @@ import type { History } from "history";
export const makeHistoryTaskQueue = (history: History) => {
let previousTask = Promise.resolve();

const enqueue = (cb: () => void) => {
const enqueue = (cb: () => void, listen: boolean = true) => {
previousTask = previousTask.then(
() =>
new Promise<void>((resolve) => {
const clean = history.listen(() => {
clean();
resolve();
});
if (listen) {
const clean = history.listen(() => {
clean();
resolve();
});
}

cb();

if (!listen) {
resolve();
}
}),
);
};
Expand Down

1 comment on commit 2a24b38

@vercel
Copy link

@vercel vercel bot commented on 2a24b38 Oct 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.