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

Class MicroSchedulerDefault

packages/effect/src/Micro.ts:1777–1826  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1775 * @category scheduler
1776 */
1777export class MicroSchedulerDefault implements MicroScheduler {
1778 private tasks: Array<() => void> = []
1779 private running = false
1780
1781 /**
1782 * @since 3.5.9
1783 */
1784 scheduleTask(task: () => void, _priority: number) {
1785 this.tasks.push(task)
1786 if (!this.running) {
1787 this.running = true
1788 setImmediate(this.afterScheduled)
1789 }
1790 }
1791
1792 /**
1793 * @since 3.5.9
1794 */
1795 afterScheduled = () => {
1796 this.running = false
1797 this.runTasks()
1798 }
1799
1800 /**
1801 * @since 3.5.9
1802 */
1803 runTasks() {
1804 const tasks = this.tasks
1805 this.tasks = []
1806 for (let i = 0, len = tasks.length; i < len; i++) {
1807 tasks[i]()
1808 }
1809 }
1810
1811 /**
1812 * @since 3.5.9
1813 */
1814 shouldYield(fiber: MicroFiber<unknown, unknown>) {
1815 return fiber.currentOpCount >= fiber.getRef(MaxOpsBeforeYield)
1816 }
1817
1818 /**
1819 * @since 3.5.9
1820 */
1821 flush() {
1822 while (this.tasks.length > 0) {
1823 this.runTasks()
1824 }
1825 }
1826}
1827
1828/**
1829 * Access the given `Context.Tag` from the environment.

Callers

nothing calls this directly

Calls 1

runTasksMethod · 0.95

Tested by

no test coverage detected