// ets_tracing: off import * as C from "../Cause/index.js" import type * as Exit from "../Exit/index.js" import type { Status } from "./status.js" import { Done, Running } from "./status.js" export type FiberState = FiberStateExecuting | FiberStateDone export type Callback = (exit: Exit.Exit) => void export class FiberStateExecuting { readonly _tag = "Executing" constructor( readonly status: Status, readonly observers: Callback>[], readonly interrupted: C.Cause ) {} } export class FiberStateDone { readonly _tag = "Done" readonly interrupted = C.empty readonly status: Status = new Done() constructor(readonly value: Exit.Exit) {} } export function initial(): FiberState { return new FiberStateExecuting(new Running(false), [], C.empty) } export function interrupting(state: FiberState): boolean { let current: Status | undefined = state.status while (current) { switch (current._tag) { case "Running": { return current.interrupting } case "Finishing": { return current.interrupting } case "Done": { return false } case "Suspended": { current = current.previous } } } throw new Error("BUG: should never end up here") }