import { LazyDisposable } from '@typed/disposable'
import { FailEnv } from '../failures'
export interface Fiber extends LazyDisposable {
info: FiberInfo // Intended to be mutable
}
export const FiberFailure = Symbol.for('FiberFailure')
export type FiberFailure = FailEnv
export const enum FiberState {
Running,
Returned,
Error,
}
export type FiberInfo =
| {
readonly state: FiberState.Running
// A promise is used because it will keep track of the value and supply the resolved/rejected value to late subscribers
readonly promise: Promise // Rejects with Error
}
| { readonly state: FiberState.Error; readonly error: Error }
| { readonly state: FiberState.Returned; readonly value: B }