MCPcopy Index your code
hub / github.com/Effect-TS/effect / SyncScheduler

Class SyncScheduler

packages/effect/src/Scheduler.ts:172–218  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

170 * @category constructors
171 */
172export class SyncScheduler implements Scheduler {
173 /**
174 * @since 2.0.0
175 */
176 tasks = new PriorityBuckets()
177
178 /**
179 * @since 2.0.0
180 */
181 deferred = false
182
183 /**
184 * @since 2.0.0
185 */
186 scheduleTask(task: Task, priority: number, fiber?: RuntimeFiber<unknown, unknown>) {
187 if (this.deferred) {
188 defaultScheduler.scheduleTask(task, priority, fiber)
189 } else {
190 this.tasks.scheduleTask(task, priority)
191 }
192 }
193
194 /**
195 * @since 2.0.0
196 */
197 shouldYield(fiber: RuntimeFiber<unknown, unknown>): number | false {
198 return fiber.currentOpCount > fiber.getFiberRef(core.currentMaxOpsBeforeYield)
199 ? fiber.getFiberRef(core.currentSchedulingPriority)
200 : false
201 }
202
203 /**
204 * @since 2.0.0
205 */
206 flush() {
207 while (this.tasks.buckets.length > 0) {
208 const tasks = this.tasks.buckets
209 this.tasks.buckets = []
210 for (const [_, toRun] of tasks) {
211 for (let i = 0; i < toRun.length; i++) {
212 toRun[i]()
213 }
214 }
215 }
216 this.deferred = true
217 }
218}
219
220/**
221 * @since 2.0.0

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…