Hyperlinkv0.9.0-beta.0

Lookup

Lookup.directoryTableconstsrc/Lookup.ts:563
(): Effect.Effect<
  {
    readonly get: Effect.Effect<ReadonlyMap<string, DirectoryEntry>>
    readonly getNode: (
      nodeKey: string
    ) => Effect.Effect<Option.Option<DirectoryEntry>>
  },
  never,
  Directory | Scope.Scope
>

Live dial table driven by Directory.changes — for node-level peer rebind.

Starts empty; applies upserts/removes as they arrive. Pair with an initial nodesServing seed when you need a cold snapshot before the first event.

constructorsDirectory.changes
Source src/Lookup.ts:56337 lines
export const directoryTable = (): Effect.Effect<
  {
    readonly get: Effect.Effect<ReadonlyMap<string, DirectoryEntry>>;
    readonly getNode: (
      nodeKey: string,
    ) => Effect.Effect<Option.Option<DirectoryEntry>>;
  },
  never,
  Directory | Scope.Scope
> =>
  Effect.gen(function* () {
    const table = yield* Ref.make(new Map<string, DirectoryEntry>());
    yield* changes.pipe(
      Stream.runForEach((event) => {
        if (event._tag === "DirectoryRemoved") {
          return Ref.update(table, (current) => {
            const next = new Map(current);
            next.delete(event.nodeKey);
            return next;
          });
        }
        return Ref.update(table, (current) => {
          const next = new Map(current);
          next.set(event.entry.nodeKey, event.entry);
          return next;
        });
      }),
      Effect.forkScoped,
    );
    return {
      get: Ref.get(table),
      getNode: (nodeKey: string) =>
        Ref.get(table).pipe(
          Effect.map((current) => Option.fromNullishOr(current.get(nodeKey))),
        ),
    };
  });