API reference@evolu/commonTask › SemaphorePolicy

type SemaphorePolicy = "fifo" | "greedy";

Defined in: packages/common/src/Task.ts:5649

Scheduling policy for semaphore acquisition.

The policy changes behavior only when requests acquire different numbers of permits. If every request acquires one permit, both policies admit requests in the same order.

"fifo" is the default fair policy. Requests are served in arrival order. Once a request is queued, later requests cannot acquire permits before it. This prevents starvation, but can leave permits unused while the oldest queued request waits for enough permits.

"greedy" is the throughput-oriented policy. A request may acquire permits as soon as it fits, even when older larger requests are waiting. This keeps more permits in use and avoids head-of-line blocking, but larger requests can starve indefinitely if smaller requests keep arriving.

Greedy scheduling is first-fit, not optimal-fit: queued requests are scanned in arrival order, and grantable requests are admitted as they are found. The semaphore does not reorder requests to maximize utilization.

Use "fifo" when fairness and predictable progress matter, such as tenant sync, API quota, or database pools where large requests must not be starved by a stream of smaller requests.

Use "greedy" when permits represent a shared budget and smaller or latency-sensitive requests should proceed around larger queued requests. For example, dashboard queries can run while analytics exports wait, thumbnail jobs can run while video transcodes wait, and small transfers can use bandwidth while large transfers are queued.