Skip to content

Commit

Permalink
fix: improve scheduling code
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-lednev committed Nov 24, 2024
1 parent dd9b30b commit 833f999
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/ui/hooks/use-idle-derived.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { derived, type Readable } from "svelte/store";

import { createBackgroundBatchScheduler } from "../../util/scheduler";

export function useIdleDerived<T>(props: {
batch: Readable<Array<() => T>>;
timeRemainingLowerLimit: number;
initial: T[];
}) {
const { batch, timeRemainingLowerLimit, initial } = props;

const scheduler = createBackgroundBatchScheduler<T>({
timeRemainingLowerLimit,
});

return derived(
batch,
($batch, set) => {
scheduler.enqueueTasks($batch, set);
},
initial,
);
}

0 comments on commit 833f999

Please sign in to comment.