queue.ts
This file
Path
packages/project/src/queue.ts
39 lines · 1.3 KiB · TypeScript
Last changed by
Merge build/comments-project into mainoscabrielbefore adoption49efd2a
History of this fileTake it
The walk stopped after 200 commits: lines older than 958650a point at it.
Merge branch 'build/905-readme-markdown'oscabrielbefore adoption958650a
lines 1–11why, one step back1import type { RequestId } from "@repo/protocol/ids";2import { Effect, Option, Schema } from "effect";34import { enqueue, LandingQueue, next as admitNext, settle } from "./landing.ts";56export const emptyQueue: LandingQueue = { active: Option.none(), order: [] };78const decodeQueue = Schema.decodeUnknownEffect(LandingQueue);910const encodeQueue = Schema.encodeEffect(LandingQueue);11Merge build/comments-project into mainoscabrielbefore adoption49efd2a
line 12why, one step back12/** `null` until a commit first writes one. */Merge branch 'build/905-readme-markdown'oscabrielbefore adoption958650a
lines 13–39why, one step back13export const queueOf = (stored: Schema.Json): Effect.Effect<LandingQueue> =>14 stored === null15 ? Effect.succeed(emptyQueue)16 : Effect.orDie(decodeQueue(stored));1718export const storedQueue = (queue: LandingQueue): Effect.Effect<Schema.Json> =>19 Effect.orDie(encodeQueue(queue));2021export const holdsSlot = (queue: LandingQueue, id: RequestId): boolean =>22 Option.contains(queue.active, id);2324export interface Moved {25 readonly admitted: Option.Option<RequestId>;26 readonly queue: LandingQueue;27}2829export const askToLand = (queue: LandingQueue, id: RequestId): Moved => {30 const { admit, queue: moved } = admitNext(enqueue(queue, id));3132 return { admitted: admit, queue: moved };33};3435export const leave = (queue: LandingQueue, id: RequestId): Moved => {36 const { admit, queue: moved } = admitNext(settle(queue, id));3738 return { admitted: admit, queue: moved };39};