MCPcopy Index your code
hub / github.com/TanStack/db / schedule

Method schedule

packages/db/src/scheduler.ts:77–104  ·  view source on GitHub ↗

* Schedule work. Without a context id, executes immediately. * Otherwise queues the job to be flushed once dependencies are satisfied. * Scheduling the same jobId again replaces the previous run function.

({ contextId, jobId, dependencies, run }: ScheduleOptions)

Source from the content-addressed store, hash-verified

75 * Scheduling the same jobId again replaces the previous run function.
76 */
77 schedule({ contextId, jobId, dependencies, run }: ScheduleOptions): void {
78 if (typeof contextId === `undefined`) {
79 run()
80 return
81 }
82
83 const context = this.getOrCreateContext(contextId)
84
85 // If this is a new job, add it to the queue
86 if (!context.jobs.has(jobId)) {
87 context.queue.push(jobId)
88 }
89
90 // Store or replace the run function
91 context.jobs.set(jobId, run)
92
93 // Update dependencies
94 if (dependencies) {
95 const depSet = new Set<unknown>(dependencies)
96 depSet.delete(jobId)
97 context.dependencies.set(jobId, depSet)
98 } else if (!context.dependencies.has(jobId)) {
99 context.dependencies.set(jobId, new Set())
100 }
101
102 // Clear completion status since we're rescheduling
103 context.completed.delete(jobId)
104 }
105
106 /**
107 * Flush all queued work for a context. Jobs with unmet dependencies are retried.

Callers 1

Calls 5

getOrCreateContextMethod · 0.95
runFunction · 0.50
hasMethod · 0.45
setMethod · 0.45
deleteMethod · 0.45

Tested by

no test coverage detected