import * as T from "../../../Effect/index.js"; import type { FiberID } from "../../../Fiber/index.js"; import type { Journal } from "../Journal/index.js"; export declare const STMTypeId: unique symbol; export declare type STMTypeId = typeof STMTypeId; /** * `STM` represents an effect that can be performed transactionally, * resulting in a failure `E` or a value `A` that may require an environment * `R` to execute. * * Software Transactional Memory is a technique which allows composition of arbitrary atomic operations. It is * the software analog of transactions in database systems. * * The API is lifted directly from the Haskell package Control.Concurrent.STM although the implementation does not * resemble the Haskell one at all. * [[http://hackage.haskell.org/package/stm-2.5.0.0/docs/Control-Concurrent-STM.html]] * * STM in Haskell was introduced in: * Composable memory transactions, by Tim Harris, Simon Marlow, Simon Peyton Jones, and Maurice Herlihy, in ACM * Conference on Principles and Practice of Parallel Programming 2005. * [[https://www.microsoft.com/en-us/research/publication/composable-memory-transactions/]] * * See also: * Lock Free Data Structures using STMs in Haskell, by Anthony Discolo, Tim Harris, Simon Marlow, Simon Peyton Jones, * Satnam Singh) FLOPS 2006: Eighth International Symposium on Functional and Logic Programming, Fuji Susono, JAPAN, * April 2006 * [[https://www.microsoft.com/en-us/research/publication/lock-free-data-structures-using-stms-in-haskell/]] * * The implemtation is based on the ZIO STM module, while JS environments have no race conditions from multiple threads * STM provides greater benefits for syncronisation of Fibers and transactional data-types can be quite useful. */ export declare abstract class STM { readonly [STMTypeId]: STMTypeId; readonly [T._R]: (_: R) => void; readonly [T._E]: () => E; readonly [T._A]: () => A; } export declare const STMEffectTypeId: unique symbol; export declare type STMEffectTypeId = typeof STMEffectTypeId; export declare class STMEffect extends STM { readonly f: (journal: Journal, fiberId: FiberID, r: R) => A; readonly _typeId: STMEffectTypeId; constructor(f: (journal: Journal, fiberId: FiberID, r: R) => A); } export declare const STMOnFailureTypeId: unique symbol; export declare type STMOnFailureTypeId = typeof STMOnFailureTypeId; export declare class STMOnFailure extends STM { readonly stm: STM; readonly onFailure: (e: E) => STM; readonly _typeId: STMOnFailureTypeId; constructor(stm: STM, onFailure: (e: E) => STM); apply(a: A): STM; } export declare const STMOnRetryTypeId: unique symbol; export declare type STMOnRetryTypeId = typeof STMOnRetryTypeId; export declare class STMOnRetry extends STM { readonly stm: STM; readonly onRetry: STM; readonly _typeId: STMOnRetryTypeId; constructor(stm: STM, onRetry: STM); apply(a: A): STM; } export declare const STMOnSuccessTypeId: unique symbol; export declare type STMOnSuccessTypeId = typeof STMOnSuccessTypeId; export declare class STMOnSuccess extends STM { readonly stm: STM; readonly apply: (a: A) => STM; readonly _typeId: STMOnSuccessTypeId; constructor(stm: STM, apply: (a: A) => STM); } export declare const STMSucceedTypeId: unique symbol; export declare type STMSucceedTypeId = typeof STMSucceedTypeId; export declare class STMSucceed extends STM { readonly a: () => A; readonly _typeId: STMSucceedTypeId; constructor(a: () => A); } export declare const STMSucceedNowTypeId: unique symbol; export declare type STMSucceedNowTypeId = typeof STMSucceedNowTypeId; export declare class STMSucceedNow extends STM { readonly a: A; readonly _typeId: STMSucceedNowTypeId; constructor(a: A); } export declare const STMProvideSomeTypeId: unique symbol; export declare type STMProvideSomeTypeId = typeof STMProvideSomeTypeId; export declare class STMProvideSome extends STM { readonly stm: STM; readonly f: (r: R) => R0; readonly _typeId: STMProvideSomeTypeId; constructor(stm: STM, f: (r: R) => R0); } /** * @ets_optimize remove */ export declare function concreteSTM(_: STM): asserts _ is STMEffect | STMOnFailure | STMOnSuccess | STMOnRetry | STMSucceed | STMSucceedNow | STMProvideSome; export declare const FailExceptionTypeId: unique symbol; export declare type FailExceptionTypeId = typeof FailExceptionTypeId; export declare class STMFailException { readonly e: E; readonly _typeId: FailExceptionTypeId; constructor(e: E); } export declare function isFailException(u: unknown): u is STMFailException; export declare const DieExceptionTypeId: unique symbol; export declare type DieExceptionTypeId = typeof DieExceptionTypeId; export declare class STMDieException { readonly e: E; readonly _typeId: DieExceptionTypeId; constructor(e: E); } export declare function isDieException(u: unknown): u is STMDieException; export declare const RetryExceptionTypeId: unique symbol; export declare type RetryExceptionTypeId = typeof RetryExceptionTypeId; export declare class STMRetryException { readonly _typeId: RetryExceptionTypeId; } export declare function isRetryException(u: unknown): u is STMRetryException; /** * Returns an `STM` effect that succeeds with the specified value. */ export declare function succeed(a: A): STM; /** * Returns an `STM` effect that succeeds with the specified value. */ export declare function succeedWith(a: () => A): STM; /** * Returns a value that models failure in the transaction. */ export declare function fail(e: E): STM; /** * Returns a value that models failure in the transaction. */ export declare function failWith(e: () => E): STM; /** * Kills the fiber running the effect. */ export declare function die(u: unknown): STM; /** * Kills the fiber running the effect. */ export declare function dieWith(u: () => unknown): STM; /** * Maps the value produced by the effect. */ export declare function map_(self: STM, f: (a: A) => B): STM; /** * Maps the value produced by the effect. * * @ets_data_first map_ */ export declare function map(f: (a: A) => B): (self: STM) => STM; /** * Feeds the value produced by this effect to the specified function, * and then runs the returned effect as well to produce its results. */ export declare function chain_(self: STM, f: (a: A) => STM): STM; /** * Feeds the value produced by this effect to the specified function, * and then runs the returned effect as well to produce its results. * * @ets_data_first chain_ */ export declare function chain(f: (a: A) => STM): (self: STM) => STM; /** * Recovers from all errors. */ export declare function catchAll_(self: STM, f: (e: E) => STM): STM; /** * Recovers from all errors. * * @ets_data_first catchAll_ */ export declare function catchAll(f: (e: E) => STM): (self: STM) => STM; /** * Effectfully folds over the `STM` effect, handling both failure and * success. */ export declare function foldM_(self: STM, g: (e: E) => STM, f: (a: A) => STM): STM; /** * Effectfully folds over the `STM` effect, handling both failure and * success. * * @ets_data_first foldM_ */ export declare function foldM(g: (e: E) => STM, f: (a: A) => STM): (self: STM) => STM; /** * Executes the specified finalization transaction whether or * not this effect succeeds. Note that as with all STM transactions, * if the full transaction fails, everything will be rolled back. */ export declare function ensuring_(self: STM, finalizer: STM): STM; /** * Executes the specified finalization transaction whether or * not this effect succeeds. Note that as with all STM transactions, * if the full transaction fails, everything will be rolled back. * * @ets_data_first ensuring_ */ export declare function ensuring(finalizer: STM): (self: STM) => STM; /** * Abort and retry the whole transaction when any of the underlying * transactional variables have changed. */ export declare const retry: STM; /** * Returns an `STM` effect that succeeds with `Unit`. */ export declare const unit: STM; /** * Provides some of the environment required to run this effect, * leaving the remainder `R0`. */ export declare function provideSome_(self: STM, f: (r: R0) => R): STM; /** * Provides some of the environment required to run this effect, * leaving the remainder `R0`. * * @ets_data_first provideSome_ */ export declare function provideSome(f: (r: R0) => R): (self: STM) => STM; //# sourceMappingURL=primitives.d.ts.map