Skip to content
Myr

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 file

Take it

The walk stopped after 200 commits: lines older than 678c8b8 point at it.

Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8

lines 1–11why, one step back
1import 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);11

Merge build/comments-project into mainoscabrielbefore adoption49efd2a

line 12why, one step back
12/** `null` until a commit first writes one. */

Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8

lines 13–39why, one step back
13export 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};