import { Base } from "../class/Base.js"; import { Atom } from "./atom/Atom.js"; import { CalculationMode, CalculationModeGen, CalculationModeSync } from "./CalculationMode.js"; /** * This is a calculation context type. It is represented with a function, that receives some value (effect) and returns the result * (effect processing results). Can be also thought as "effect handler". * * When using generators-based calculation, there's no need to use this function directly - the syntax construct `yield` plays its role. */ export declare type EffectHandler = Mode extends CalculationModeSync ? (effect: unknown) => any : Mode extends CalculationModeGen ? (effect: unknown) => any : never; export declare function runGeneratorAsyncWithEffect(onEffect: EffectHandler, func: (...args: ArgsT) => Generator, args: ArgsT, scope?: any): Promise; export declare function runGeneratorSyncWithEffect(onEffect: EffectHandler, func: (...args: ArgsT) => Generator, args: ArgsT, scope?: any): ResultT; /** * The base class for effect. Effect is some value, that can be send to the "outer" calculation context, using the * effect handler function. Effect handler then will process an effect and return some resulting value. * * ```ts * const identifier = graph.identifier((Y : SyncEffectHandler) : number => { * const proposedValue : number = Y(ProposedOrPrevious) * * const maxValue : number = Y(max) * * return proposedValue <= maxValue ? proposedValue : maxValue * }) * ``` */ export declare class Effect extends Base { handler: symbol; /** * Whether the effect is synchronous. Default value, defined in the prototype, is `true`. */ sync: boolean; internal: boolean; } export declare const ProposedOrPreviousSymbol: unique symbol; /** * The constant that represents a request for either user input (proposed value) or previous value of the * identifier, currently being calculated. * * Important note, is that if an identifier yields a `ProposedOrPrevious` effect and its computed value does not match the value of this effect, * it will be re-calculated (computation function called) again on the next read. This is because the value of its `ProposedOrPrevious` input changes. * * ```ts * const graph4 = ChronoGraph.new() * * const max = graph4.variable(100) * * const identifier15 = graph4.identifier((Y) : number => { * const proposedValue : number = Y(ProposedOrPrevious) * * const maxValue : number = Y(max) * * return proposedValue <= maxValue ? proposedValue : maxValue * }) * * graph4.write(identifier15, 18) * * const value15_1 = graph4.read(identifier15) // 18 * * graph4.write(identifier15, 180) * * const value15_2 = graph4.read(identifier15) // 100 * * graph4.write(max, 50) * * const value15_3 = graph4.read(identifier15) // 50 * ``` */ export declare const ProposedOrPrevious: Effect; export declare const RejectSymbol: unique symbol; /** * Class for [[Reject]] effect. */ export declare class RejectEffect extends Effect { handler: symbol; /** * Reason of the reject */ reason: Reason; } /** * This is constructor for `RejectEffect` class. If this effect will be yielded during computation the current transaction * will be [[ChronoGraph.reject|rejected]]. * * @param reason * @constructor */ export declare const Reject: (reason: Reason) => RejectEffect; export declare const PreviousValueOfSymbol: unique symbol; export declare class PreviousValueOfEffect extends Effect { handler: symbol; atom: Atom; } export declare const PreviousValueOf: (atom: Atom) => PreviousValueOfEffect; export declare const ProposedValueOfSymbol: unique symbol; export declare class ProposedValueOfEffect extends Effect { handler: symbol; atom: Atom; } export declare const ProposedValueOf: (atom: Atom) => ProposedValueOfEffect; export declare const HasProposedValueSymbol: unique symbol; export declare class HasProposedValueEffect extends Effect { handler: symbol; atom: Atom; } export declare const HasProposedValue: (atom: Atom) => HasProposedValueEffect; export declare const ProposedOrPreviousValueOfSymbol: unique symbol; export declare class ProposedOrPreviousValueOfEffect extends Effect { handler: symbol; atom: Atom; } export declare const ProposedOrPreviousValueOf: (atom: Atom) => ProposedOrPreviousValueOfEffect; export declare const ProposedArgumentsOfSymbol: unique symbol; export declare class ProposedArgumentsOfEffect extends Effect { handler: symbol; atom: Atom; } export declare const ProposedArgumentsOf: (atom: Atom) => ProposedArgumentsOfEffect; export declare type ProgressNotificationEffect = { total: number; remaining: number; phase: string; };