Socket
Socket
Sign inDemoInstall

@effect/io

Package Overview
Dependencies
Maintainers
3
Versions
183
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@effect/io - npm Package Compare versions

Comparing version 0.0.28 to 0.0.29

2

internal/core.d.ts
import type * as Effect from "@effect/io/Effect";
import * as OpCodes from "@effect/io/internal/opCodes/effect";
export interface Commit extends Op<OpCodes.OP_COMMIT, {
readonly commit: Effect.Effect<unknown, unknown, unknown>;
commit(): Effect.Effect<unknown, unknown, unknown>;
}> {
}
//# sourceMappingURL=core.d.ts.map

@@ -16,6 +16,18 @@ import type * as Effect from "@effect/io/Effect";

export declare const unsafeMakeSemaphore: (permits: number) => Semaphore;
/**
* @macro traced
*/
export declare const acquireN: (n: number) => (self: Semaphore) => STM.STM<never, never, void>;
/**
* @macro traced
*/
export declare const releaseN: (n: number) => (self: Semaphore) => STM.STM<never, never, void>;
/**
* @macro traced
*/
export declare const withPermits: (permits: number) => (semaphore: Semaphore) => <R, E, A>(self: Effect.Effect<R, E, A>) => Effect.Effect<R, E, A>;
/**
* @macro traced
*/
export declare const withPermitsScoped: (permits: number) => (self: Semaphore) => Effect.Effect<Scope.Scope, never, void>;
//# sourceMappingURL=circular.d.ts.map

@@ -430,41 +430,57 @@ "use strict";

};
/**
* @macro traced
*/
exports.unsafeMakeSemaphore = unsafeMakeSemaphore;
const acquireN = n => {
const trace = (0, _Debug.getCallTrace)();
return self => {
return STM.effect(journal => {
return STM.withSTMRuntime(_ => {
if (n < 0) {
throw Cause.IllegalArgumentException(`Unexpected negative value ${n} passed to Semaphore.acquireN`);
}
const value = TRef.unsafeGet(journal)(self.permits);
const value = TRef.unsafeGet(_.journal)(self.permits);
if (value < n) {
throw new STM.STMRetryException();
return STM.retry();
} else {
return TRef.unsafeSet(value - n, journal)(self.permits);
return STM.succeed(TRef.unsafeSet(value - n, _.journal)(self.permits));
}
});
}).traced(trace);
};
};
/**
* @macro traced
*/
exports.acquireN = acquireN;
const releaseN = n => {
const trace = (0, _Debug.getCallTrace)();
return self => {
return STM.effect(journal => {
return STM.withSTMRuntime(_ => {
if (n < 0) {
throw Cause.IllegalArgumentException(`Unexpected negative value ${n} passed to Semaphore.releaseN`);
}
const current = TRef.unsafeGet(journal)(self.permits);
return TRef.unsafeSet(current + n, journal)(self.permits);
});
const current = TRef.unsafeGet(_.journal)(self.permits);
return STM.succeed(TRef.unsafeSet(current + n, _.journal)(self.permits));
}).traced(trace);
};
};
/**
* @macro traced
*/
exports.releaseN = releaseN;
const withPermits = permits => {
const trace = (0, _Debug.getCallTrace)();
return semaphore => {
return self => {
return core.uninterruptibleMask(restore => core.zipRight(ensuring(STM.commit(releaseN(permits)(semaphore)))(restore(self)))(restore(STM.commit(acquireN(permits)(semaphore)))));
return core.uninterruptibleMask(restore => core.zipRight(ensuring(STM.commit(releaseN(permits)(semaphore)))(restore(self)))(restore(STM.commit(acquireN(permits)(semaphore))))).traced(trace);
};
};
};
/**
* @macro traced
*/
exports.withPermits = withPermits;
const withPermitsScoped = permits => {
return self => acquireReleaseInterruptible(STM.commit(acquireN(permits)(self)), () => STM.commit(releaseN(permits)(self)));
const trace = (0, _Debug.getCallTrace)();
return self => acquireReleaseInterruptible(STM.commit(acquireN(permits)(self)), () => STM.commit(releaseN(permits)(self))).traced(trace);
};

@@ -471,0 +487,0 @@ // circular with Fiber

@@ -6,7 +6,7 @@ "use strict";

});
exports.OP_SUCCEED_NOW = exports.OP_SUCCEED = exports.OP_PROVIDE = exports.OP_ON_SUCCESS = exports.OP_ON_RETRY = exports.OP_ON_FAILURE = exports.OP_EFFECT = void 0;
exports.OP_WITH_STM_RUNTIME = exports.OP_SYNC = exports.OP_SUCCEED = exports.OP_RETRY = exports.OP_PROVIDE = exports.OP_ON_SUCCESS = exports.OP_ON_RETRY = exports.OP_ON_FAILURE = exports.OP_INTERRUPT = exports.OP_FAIL = exports.OP_DIE = void 0;
/** @internal */
const OP_EFFECT = 0;
const OP_WITH_STM_RUNTIME = 0;
/** @internal */
exports.OP_EFFECT = OP_EFFECT;
exports.OP_WITH_STM_RUNTIME = OP_WITH_STM_RUNTIME;
const OP_ON_FAILURE = 1;

@@ -24,7 +24,19 @@ /** @internal */

exports.OP_PROVIDE = OP_PROVIDE;
const OP_SUCCEED = 5;
const OP_SYNC = 5;
/** @internal */
exports.OP_SYNC = OP_SYNC;
const OP_SUCCEED = 6;
/** @internal */
exports.OP_SUCCEED = OP_SUCCEED;
const OP_SUCCEED_NOW = 6;
exports.OP_SUCCEED_NOW = OP_SUCCEED_NOW;
const OP_RETRY = 7;
/** @internal */
exports.OP_RETRY = OP_RETRY;
const OP_FAIL = 8;
/** @internal */
exports.OP_FAIL = OP_FAIL;
const OP_DIE = 9;
/** @internal */
exports.OP_DIE = OP_DIE;
const OP_INTERRUPT = 10;
exports.OP_INTERRUPT = OP_INTERRUPT;
//# sourceMappingURL=stm.js.map

@@ -5,8 +5,26 @@ import type * as Effect from "@effect/io/Effect";

import type * as Scope from "@effect/io/Scope";
/**
* @macro traced
*/
export declare const make: (permits: number) => STM.STM<never, never, circular.Semaphore>;
/**
* @macro traced
*/
export declare function available(self: circular.Semaphore): STM.STM<never, never, number>;
/**
* @macro traced
*/
export declare const acquire: (self: circular.Semaphore) => STM.STM<never, never, void>;
/**
* @macro traced
*/
export declare const release: (self: circular.Semaphore) => STM.STM<never, never, void>;
/**
* @macro traced
*/
export declare const withPermit: (semaphore: circular.Semaphore) => <R, E, A>(self: Effect.Effect<R, E, A>) => Effect.Effect<R, E, A>;
/**
* @macro traced
*/
export declare const withPermitScoped: (self: circular.Semaphore) => Effect.Effect<Scope.Scope, never, void>;
//# sourceMappingURL=semaphore.d.ts.map

@@ -9,2 +9,3 @@ "use strict";

exports.withPermitScoped = exports.withPermit = exports.release = exports.make = void 0;
var _Debug = /*#__PURE__*/require("@effect/io/Debug");
var circular = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/io/internal/effect/circular"));

@@ -16,27 +17,51 @@ var STM = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/io/internal/stm"));

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
/**
* @macro traced
*/
const make = permits => {
return STM.map(permits => new circular.SemaphoreImpl(permits))(Ref.make(() => permits));
const trace = (0, _Debug.getCallTrace)();
return STM.map(permits => new circular.SemaphoreImpl(permits))(Ref.make(permits)).traced(trace);
};
/**
* @macro traced
*/
exports.make = make;
function available(self) {
return Ref.get(self.permits);
const trace = (0, _Debug.getCallTrace)();
return Ref.get(self.permits).traced(trace);
}
/**
* @macro traced
*/
const acquire = self => {
return circular.acquireN(1)(self);
const trace = (0, _Debug.getCallTrace)();
return circular.acquireN(1)(self).traced(trace);
};
/**
* @macro traced
*/
exports.acquire = acquire;
const release = self => {
return circular.releaseN(1)(self);
const trace = (0, _Debug.getCallTrace)();
return circular.releaseN(1)(self).traced(trace);
};
/**
* @macro traced
*/
exports.release = release;
const withPermit = semaphore => {
const trace = (0, _Debug.getCallTrace)();
return self => {
return circular.withPermits(1)(semaphore)(self);
return circular.withPermits(1)(semaphore)(self).traced(trace);
};
};
/**
* @macro traced
*/
exports.withPermit = withPermit;
const withPermitScoped = self => {
return circular.withPermitsScoped(1)(self);
const trace = (0, _Debug.getCallTrace)();
return circular.withPermitsScoped(1)(self).traced(trace);
};
exports.withPermitScoped = withPermitScoped;
//# sourceMappingURL=semaphore.js.map

@@ -7,2 +7,3 @@ import type * as Effect from "@effect/io/Effect";

import * as Journal from "@effect/io/internal/stm/journal";
import * as Chunk from "@fp-ts/data/Chunk";
import type * as Context from "@fp-ts/data/Context";

@@ -22,3 +23,7 @@ export declare const STMTypeId: unique symbol;

}
export type Primitive = STMEffect | STMOnFailure | STMOnRetry | STMOnSuccess | STMProvide | STMSucceed | STMSucceedNow;
export type Primitive = STMEffect | STMOnFailure | STMOnRetry | STMOnSuccess | STMProvide | STMSync | STMSucceed | STMRetry | STMFail | STMDie | STMInterrupt;
/**
* @macro traced
*/
export declare const commit: <R, E, A>(self: STM<R, E, A>) => Effect.Effect<R, E, A>;
type STMOp<OpCode extends number, Body = {}> = STM<never, never, never> & Body & {

@@ -28,4 +33,4 @@ readonly op: EffectOpCodes.OP_COMMIT;

};
interface STMEffect extends STMOp<STMOpCodes.OP_EFFECT, {
readonly evaluate: (journal: Journal.Journal, fiberId: FiberId.FiberId, context: Context.Context<unknown>) => unknown;
interface STMEffect extends STMOp<STMOpCodes.OP_WITH_STM_RUNTIME, {
readonly evaluate: (runtime: STMDriver<unknown, unknown, unknown>) => STM<unknown, unknown, unknown>;
}> {

@@ -39,3 +44,2 @@ }

interface STMOnRetry extends STMOp<STMOpCodes.OP_ON_RETRY, {
readonly opSTM: STMOpCodes.OP_ON_RETRY;
readonly first: STM<unknown, unknown, unknown>;

@@ -55,76 +59,95 @@ readonly retryK: () => STM<unknown, unknown, unknown>;

}
interface STMSucceed extends STMOp<STMOpCodes.OP_SUCCEED, {
readonly opSTM: STMOpCodes.OP_SUCCEED;
interface STMSync extends STMOp<STMOpCodes.OP_SYNC, {
readonly evaluate: () => unknown;
}> {
}
interface STMSucceedNow extends STMOp<STMOpCodes.OP_SUCCEED_NOW, {
readonly opSTM: STMOpCodes.OP_SUCCEED_NOW;
interface STMSucceed extends STMOp<STMOpCodes.OP_SUCCEED, {
readonly value: unknown;
}> {
}
export declare const STMFailExceptionTypeId: unique symbol;
export type STMFailExceptionTypeId = typeof STMFailExceptionTypeId;
export interface STMFailException<E> {
readonly [STMFailExceptionTypeId]: STMFailExceptionTypeId;
readonly error: E;
interface STMRetry extends STMOp<STMOpCodes.OP_RETRY, {}> {
}
export declare class STMFailException<E> implements STMFailException<E> {
readonly error: E;
readonly [STMFailExceptionTypeId]: STMFailExceptionTypeId;
constructor(error: E);
interface STMFail extends STMOp<STMOpCodes.OP_FAIL, {
readonly error: unknown;
}> {
}
export declare const isFailException: (u: unknown) => u is STMFailException<unknown>;
export declare const STMDieExceptionTypeId: unique symbol;
export type STMDieExceptionTypeId = typeof STMDieExceptionTypeId;
export interface STMDieException {
readonly [STMDieExceptionTypeId]: STMDieExceptionTypeId;
interface STMDie extends STMOp<STMOpCodes.OP_DIE, {
readonly defect: unknown;
}> {
}
export declare class STMDieException implements STMDieException {
readonly defect: unknown;
readonly [STMDieExceptionTypeId]: STMDieExceptionTypeId;
constructor(defect: unknown);
interface STMInterrupt extends STMOp<STMOpCodes.OP_INTERRUPT, {}> {
}
export declare const isDieException: (u: unknown) => u is STMDieException;
export declare const STMInterruptExceptionTypeId: unique symbol;
export type STMInterruptExceptionTypeId = typeof STMInterruptExceptionTypeId;
export interface STMInterruptException {
readonly [STMInterruptExceptionTypeId]: STMInterruptExceptionTypeId;
readonly fiberId: FiberId.FiberId;
}
export declare class STMInterruptException implements STMInterruptException {
readonly fiberId: FiberId.FiberId;
readonly [STMInterruptExceptionTypeId]: STMInterruptExceptionTypeId;
constructor(fiberId: FiberId.FiberId);
}
export declare const isInterruptException: (u: unknown) => u is STMInterruptException;
export declare const STMRetryExceptionTypeId: unique symbol;
export type STMRetryExceptionTypeId = typeof STMRetryExceptionTypeId;
export interface STMRetryException {
readonly [STMRetryExceptionTypeId]: STMRetryExceptionTypeId;
}
export declare class STMRetryException {
readonly [STMRetryExceptionTypeId]: STMRetryExceptionTypeId;
}
export declare const isRetryException: (u: unknown) => u is STMRetryException;
export declare function effect<R, A>(f: (journal: Journal.Journal, fiberId: FiberId.FiberId, context: Context.Context<R>) => A): STM<R, never, A>;
/**
* @macro traced
*/
export declare function withSTMRuntime<R, E, A>(f: (runtime: STMDriver<unknown, unknown, unknown>) => STM<R, E, A>): STM<R, E, A>;
/**
* @macro traced
*/
export declare const fail: <E>(error: E) => STM<never, E, never>;
/**
* @macro traced
*/
export declare const die: (defect: unknown) => STM<never, never, never>;
/**
* @macro traced
*/
export declare const interrupt: () => STM<never, never, never>;
/**
* @macro traced
*/
export declare const retry: () => STM<never, never, never>;
/**
* @macro traced
*/
export declare const succeed: <A>(value: A) => STM<never, never, A>;
/**
* @macro traced
*/
export declare const sync: <A>(evaluate: () => A) => STM<never, never, A>;
/**
* @macro traced
*/
export declare const catchAll: <E, R1, E1, B>(f: (e: E) => STM<R1, E1, B>) => <R, A>(self: STM<R, E, A>) => STM<R1 | R, E1, B | A>;
/**
* @macro traced
*/
export declare const orTry: <R1, E1, A1>(that: () => STM<R1, E1, A1>) => <R, E, A>(self: STM<R, E, A>) => STM<R1 | R, E1 | E, A1 | A>;
/**
* @macro traced
*/
export declare const flatMap: <A, R1, E1, A2>(f: (a: A) => STM<R1, E1, A2>) => <R, E>(self: STM<R, E, A>) => STM<R1 | R, E1 | E, A2>;
/**
* @macro traced
*/
export declare const provideSomeEnvironment: <R0, R>(f: (context: Context.Context<R0>) => Context.Context<R>) => <E, A>(self: STM<R, E, A>) => STM<R0, E, A>;
/**
* @macro traced
*/
export declare const map: <A, B>(f: (a: A) => B) => <R, E>(self: STM<R, E, A>) => STM<R, E, B>;
/**
* @macro traced
*/
export declare const foldSTM: <E, R1, E1, A1, A, R2, E2, A2>(onFailure: (e: E) => STM<R1, E1, A1>, onSuccess: (a: A) => STM<R2, E2, A2>) => <R>(self: STM<R, E, A>) => STM<R1 | R2 | R, E1 | E2, A1 | A2>;
/**
* @macro traced
*/
export declare const ensuring: <R1, B>(finalizer: STM<R1, never, B>) => <R, E, A>(self: STM<R, E, A>) => STM<R1 | R, E, A>;
/**
* @macro traced
*/
export declare const zip: <R1, E1, A1>(that: STM<R1, E1, A1>) => <R, E, A>(self: STM<R, E, A>) => STM<R1 | R, E1 | E, readonly [A, A1]>;
/**
* @macro traced
*/
export declare const zipLeft: <R1, E1, A1>(that: STM<R1, E1, A1>) => <R, E, A>(self: STM<R, E, A>) => STM<R1 | R, E1 | E, A>;
/**
* @macro traced
*/
export declare const zipRight: <R1, E1, A1>(that: STM<R1, E1, A1>) => <R, E, A>(self: STM<R, E, A>) => STM<R1 | R, E1 | E, A1>;
/**
* @macro traced
*/
export declare const zipWith: <R1, E1, A1, A, A2>(that: STM<R1, E1, A1>, f: (a: A, b: A1) => A2) => <R, E>(self: STM<R, E, A>) => STM<R1 | R, E1 | E, A2>;
export declare const commit: <R, E, A>(self: STM<R, E, A>) => Effect.Effect<R, E, A>;
type Continuation = STMOnFailure | STMOnSuccess | STMOnRetry;
export declare class STMDriver<R, E, A> {

@@ -134,7 +157,14 @@ readonly self: STM<R, E, A>;

readonly fiberId: FiberId.FiberId;
private yieldOpCount;
private contStack;
private envStack;
private env;
private execution;
private tracesInStack;
constructor(self: STM<R, E, A>, journal: Journal.Journal, fiberId: FiberId.FiberId, r0: Context.Context<R>);
private unwindStack;
private logTrace;
pushStack(cont: Continuation): void;
popStack(): Continuation | undefined;
stackToLines(): Chunk.Chunk<string>;
nextSuccess(): STMOnSuccess | undefined;
nextFailure(): STMOnFailure | undefined;
nextRetry(): STMOnRetry | undefined;
run(): TExit.Exit<E, A>;

@@ -141,0 +171,0 @@ }

@@ -6,7 +6,9 @@ "use strict";

});
exports.die = exports.commit = exports.catchAll = exports.STMTypeId = exports.STMRetryExceptionTypeId = exports.STMRetryException = exports.STMInterruptExceptionTypeId = exports.STMInterruptException = exports.STMFailExceptionTypeId = exports.STMFailException = exports.STMDriver = exports.STMDieExceptionTypeId = exports.STMDieException = void 0;
exports.effect = effect;
exports.zipWith = exports.zipRight = exports.zipLeft = exports.zip = exports.sync = exports.succeed = exports.retry = exports.provideSomeEnvironment = exports.orTry = exports.map = exports.isRetryException = exports.isInterruptException = exports.isFailException = exports.isDieException = exports.interrupt = exports.foldSTM = exports.flatMap = exports.fail = exports.ensuring = void 0;
exports.sync = exports.succeed = exports.retry = exports.provideSomeEnvironment = exports.orTry = exports.map = exports.interrupt = exports.foldSTM = exports.flatMap = exports.fail = exports.ensuring = exports.die = exports.commit = exports.catchAll = exports.STMTypeId = exports.STMDriver = void 0;
exports.withSTMRuntime = withSTMRuntime;
exports.zipWith = exports.zipRight = exports.zipLeft = exports.zip = void 0;
var Cause = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/io/Cause"));
var _Debug = /*#__PURE__*/require("@effect/io/Debug");
var Exit = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/io/Exit"));
var _cause = /*#__PURE__*/require("@effect/io/internal/cause");
var core = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/io/internal/core"));

@@ -16,3 +18,2 @@ var EffectOpCodes = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/io/internal/opCodes/effect"));

var _stack = /*#__PURE__*/require("@effect/io/internal/stack");
var Entry = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/io/internal/stm/entry"));
var TExit = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/io/internal/stm/exit"));

@@ -23,2 +24,4 @@ var Journal = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/io/internal/stm/journal"));

var TxnId = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/io/internal/stm/txnId"));
var _support = /*#__PURE__*/require("@effect/io/internal/support");
var Chunk = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fp-ts/data/Chunk"));
var Either = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fp-ts/data/Either"));

@@ -30,3 +33,2 @@ var Equal = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fp-ts/data/Equal"));

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
var _a, _b, _c, _d;
const STMTypeId = /*#__PURE__*/Symbol.for("@effect/stm/STM");

@@ -39,62 +41,76 @@ exports.STMTypeId = STMTypeId;

};
const proto = /*#__PURE__*/Object.assign({}, core.proto, {
/**
* @macro traced
*/
const commit = self => {
const trace = (0, _Debug.getCallTrace)();
return core.withFiberRuntime(state => {
const fiberId = state.id();
const env = state.getFiberRef(core.currentEnvironment);
const scheduler = state.getFiberRef(core.currentScheduler);
const commitResult = tryCommitSync(fiberId, self, env, scheduler);
switch (commitResult.op) {
case 0:
{
return core.done(commitResult.exit);
}
case 1:
{
const txnId = TxnId.make();
const state = MutableRef.make(STMState.running);
const io = core.async(k => {
if (STMState.isRunning(MutableRef.get(state))) {
if (Journal.isInvalid(commitResult.journal)) {
const result = tryCommit(fiberId, self, state, env, scheduler);
switch (result.op) {
case 0:
{
completeTryCommit(result.exit, k);
break;
}
case 1:
{
Journal.addTodo(txnId, result.journal, () => tryCommitAsync(fiberId, self, txnId, state, env, scheduler, k));
break;
}
}
} else {
Journal.addTodo(txnId, commitResult.journal, () => tryCommitAsync(fiberId, self, txnId, state, env, scheduler, k));
}
}
});
return core.uninterruptibleMask(restore => core.catchAllCause(cause => {
let currentState = MutableRef.get(state);
if (Equal.equals(currentState, STMState.running)) {
MutableRef.set(STMState.interrupted)(state);
}
currentState = MutableRef.get(state);
return currentState.op === 0 ? core.done(currentState.exit) : core.failCause(cause);
})(restore(io)));
}
}
}).traced(trace);
};
exports.commit = commit;
const proto = /*#__PURE__*/Object.assign({}, {
...core.proto,
[STMTypeId]: stmVariance,
op: 1
op: 1,
commit() {
return commit(this);
},
traced(trace) {
if (!(0, _Debug.isTraceEnabled)() || trace === this["trace"]) {
return this;
}
const fresh = Object.create(proto);
Object.assign(fresh, this);
fresh.trace = trace;
return fresh;
}
});
const STMFailExceptionTypeId = /*#__PURE__*/Symbol.for("@effect/stm/STM/FailException");
exports.STMFailExceptionTypeId = STMFailExceptionTypeId;
class STMFailException {
constructor(error) {
this.error = error;
this[_a] = STMFailExceptionTypeId;
}
}
exports.STMFailException = STMFailException;
_a = STMFailExceptionTypeId;
const isFailException = u => {
return typeof u === "object" && u != null && STMFailExceptionTypeId in u;
};
exports.isFailException = isFailException;
const STMDieExceptionTypeId = /*#__PURE__*/Symbol.for("@effect/stm/STM/DieException");
exports.STMDieExceptionTypeId = STMDieExceptionTypeId;
class STMDieException {
constructor(defect) {
this.defect = defect;
this[_b] = STMDieExceptionTypeId;
}
}
exports.STMDieException = STMDieException;
_b = STMDieExceptionTypeId;
const isDieException = u => {
return typeof u === "object" && u != null && STMDieExceptionTypeId in u;
};
exports.isDieException = isDieException;
const STMInterruptExceptionTypeId = /*#__PURE__*/Symbol.for("@effect/stm/STM/InterruptException");
exports.STMInterruptExceptionTypeId = STMInterruptExceptionTypeId;
class STMInterruptException {
constructor(fiberId) {
this.fiberId = fiberId;
this[_c] = STMInterruptExceptionTypeId;
}
}
exports.STMInterruptException = STMInterruptException;
_c = STMInterruptExceptionTypeId;
const isInterruptException = u => {
return typeof u === "object" && u != null && STMInterruptExceptionTypeId in u;
};
exports.isInterruptException = isInterruptException;
const STMRetryExceptionTypeId = /*#__PURE__*/Symbol.for("@effect/stm/STM/RetryException");
exports.STMRetryExceptionTypeId = STMRetryExceptionTypeId;
class STMRetryException {
constructor() {
this[_d] = STMRetryExceptionTypeId;
}
}
exports.STMRetryException = STMRetryException;
_d = STMRetryExceptionTypeId;
const isRetryException = u => {
return typeof u === "object" && u != null && STMRetryExceptionTypeId in u;
};
exports.isRetryException = isRetryException;
function effect(f) {
/**
* @macro traced
*/
function withSTMRuntime(f) {
const trace = (0, _Debug.getCallTrace)();

@@ -107,25 +123,53 @@ const stm = Object.create(proto);

}
/**
* @macro traced
*/
const fail = error => {
return effect(() => {
throw new STMFailException(error);
});
const trace = (0, _Debug.getCallTrace)();
const stm = Object.create(proto);
stm.opSTM = 8;
stm.error = error;
stm.trace = trace;
return stm;
};
/**
* @macro traced
*/
exports.fail = fail;
const die = defect => {
return effect(() => {
throw new STMDieException(defect);
});
const trace = (0, _Debug.getCallTrace)();
const stm = Object.create(proto);
stm.opSTM = 9;
stm.defect = defect;
stm.trace = trace;
return stm;
};
/**
* @macro traced
*/
exports.die = die;
const interrupt = () => {
return effect((_, fiberId) => {
throw new STMInterruptException(fiberId);
const trace = (0, _Debug.getCallTrace)();
return withSTMRuntime(_ => {
const stm = Object.create(proto);
stm.opSTM = 10;
stm.trace = trace;
stm.fiberId = _.fiberId;
return stm;
});
};
/**
* @macro traced
*/
exports.interrupt = interrupt;
const retry = () => {
return effect(() => {
throw new STMRetryException();
});
const trace = (0, _Debug.getCallTrace)();
const stm = Object.create(proto);
stm.opSTM = 7;
stm.trace = trace;
return stm;
};
/**
* @macro traced
*/
exports.retry = retry;

@@ -140,2 +184,5 @@ const succeed = value => {

};
/**
* @macro traced
*/
exports.succeed = succeed;

@@ -150,2 +197,5 @@ const sync = evaluate => {

};
/**
* @macro traced
*/
exports.sync = sync;

@@ -163,2 +213,5 @@ const catchAll = f => {

};
/**
* @macro traced
*/
exports.catchAll = catchAll;

@@ -176,2 +229,5 @@ const orTry = that => {

};
/**
* @macro traced
*/
exports.orTry = orTry;

@@ -189,2 +245,5 @@ const flatMap = f => {

};
/**
* @macro traced
*/
exports.flatMap = flatMap;

@@ -202,10 +261,18 @@ const provideSomeEnvironment = f => {

};
/**
* @macro traced
*/
exports.provideSomeEnvironment = provideSomeEnvironment;
const map = f => {
const trace = (0, _Debug.getCallTrace)();
return self => {
return flatMap(a => sync(() => f(a)))(self);
return flatMap(a => sync(() => f(a)))(self).traced(trace);
};
};
/**
* @macro traced
*/
exports.map = map;
const foldSTM = (onFailure, onSuccess) => {
const trace = (0, _Debug.getCallTrace)();
return self => {

@@ -223,63 +290,54 @@ return flatMap(either => {

}
})(catchAll(e => map(Either.left)(onFailure(e)))(map(Either.right)(self)));
})(catchAll(e => map(Either.left)(onFailure(e)))(map(Either.right)(self))).traced(trace);
};
};
/**
* @macro traced
*/
exports.foldSTM = foldSTM;
const ensuring = finalizer => {
return self => foldSTM(e => zipRight(fail(e))(finalizer), a => zipRight(succeed(a))(finalizer))(self);
const trace = (0, _Debug.getCallTrace)();
return self => foldSTM(e => zipRight(fail(e))(finalizer), a => zipRight(succeed(a))(finalizer))(self).traced(trace);
};
/**
* @macro traced
*/
exports.ensuring = ensuring;
const zip = that => {
const trace = (0, _Debug.getCallTrace)();
return self => {
return zipWith(that, (a, a1) => [a, a1])(self);
return zipWith(that, (a, a1) => [a, a1])(self).traced(trace);
};
};
/**
* @macro traced
*/
exports.zip = zip;
const zipLeft = that => {
const trace = (0, _Debug.getCallTrace)();
return self => {
return flatMap(a => map(() => a)(that))(self);
return flatMap(a => map(() => a)(that))(self).traced(trace);
};
};
/**
* @macro traced
*/
exports.zipLeft = zipLeft;
const zipRight = that => {
const trace = (0, _Debug.getCallTrace)();
return self => {
return flatMap(() => that)(self);
return flatMap(() => that)(self).traced(trace);
};
};
/**
* @macro traced
*/
exports.zipRight = zipRight;
const zipWith = (that, f) => {
const trace = (0, _Debug.getCallTrace)();
return self => {
return flatMap(a => map(b => f(a, b))(that))(self);
return flatMap(a => map(b => f(a, b))(that))(self).traced(trace);
};
};
exports.zipWith = zipWith;
const commit = self => {
return core.withFiberRuntime(state => {
const fiberId = state.id();
const env = state.getFiberRef(core.currentEnvironment);
const scheduler = state.getFiberRef(core.currentScheduler);
const commitResult = tryCommitSync(fiberId, self, env, scheduler);
switch (commitResult.op) {
case 0:
{
return core.done(commitResult.exit);
}
case 1:
{
const txnId = TxnId.make();
const state = MutableRef.make(STMState.running);
const io = core.async(tryCommitAsync(commitResult.journal, fiberId, self, txnId, state, env, scheduler));
return core.uninterruptibleMask(restore => core.catchAllCause(cause => {
let currentState = MutableRef.get(state);
if (Equal.equals(currentState, STMState.running)) {
MutableRef.set(STMState.interrupted)(state);
}
currentState = MutableRef.get(state);
return currentState.op === 0 ? core.done(currentState.exit) : core.failCause(cause);
})(restore(io)));
}
}
});
};
exports.commit = commit;
class STMDriver {

@@ -290,95 +348,136 @@ constructor(self, journal, fiberId, r0) {

this.fiberId = fiberId;
this.yieldOpCount = 2048;
this.envStack = new _stack.Stack(r0);
this.tracesInStack = 0;
this.env = r0;
}
unwindStack(error, isRetry) {
let result = undefined;
while (this.contStack && result === undefined) {
const cont = this.contStack.value;
logTrace(trace) {
if (trace) {
if (!this.execution) {
this.execution = new _support.RingBuffer(_Debug.runtimeDebug.traceExecutionLimit);
}
this.execution.push(trace);
}
}
pushStack(cont) {
this.contStack = new _stack.Stack(cont, this.contStack);
if ("trace" in cont) {
this.tracesInStack++;
}
}
popStack() {
if (this.contStack) {
const current = this.contStack;
this.contStack = this.contStack.previous;
if (cont.opSTM === 1) {
if (!isRetry) {
result = cont.failK(error);
}
if ("trace" in current.value) {
this.tracesInStack--;
}
if (cont.opSTM === 2) {
if (isRetry) {
result = cont.retryK();
}
return current.value;
}
return;
}
stackToLines() {
if (this.tracesInStack === 0) {
return Chunk.empty;
}
const lines = [];
let current = this.contStack;
let last = undefined;
let seen = 0;
while (current !== undefined && lines.length < _Debug.runtimeDebug.traceStackLimit && seen < this.tracesInStack) {
switch (current.value.opSTM) {
case 3:
case 1:
case 2:
{
if (current.value.trace) {
seen++;
if (current.value.trace !== last) {
last = current.value.trace;
lines.push(current.value.trace);
}
}
break;
}
}
current = current.previous;
}
return result;
return Chunk.unsafeFromArray(lines);
}
nextSuccess() {
let current = this.popStack();
while (current && current.opSTM !== 3) {
current = this.popStack();
}
return current;
}
nextFailure() {
let current = this.popStack();
while (current && current.opSTM !== 1) {
current = this.popStack();
}
return current;
}
nextRetry() {
let current = this.popStack();
while (current && current.opSTM !== 2) {
current = this.popStack();
}
return current;
}
run() {
let curr = this.self;
let exit = undefined;
let opCount = 0;
while (exit === undefined && curr !== undefined) {
if (opCount === this.yieldOpCount) {
let valid = true;
for (const [, entry] of this.journal) {
valid = Entry.isValid(entry);
}
if (!valid) {
exit = TExit.retry;
} else {
opCount = 0;
}
} else {
try {
const current = curr;
switch (current.opSTM) {
case 0:
case 9:
{
try {
const a = current.evaluate(this.journal, this.fiberId, this.envStack.value);
if (!this.contStack) {
exit = TExit.succeed(a);
} else {
const cont = this.contStack.value;
this.contStack = this.contStack.previous;
if (cont.opSTM === 1 || cont.opSTM === 2) {
curr = succeed(a);
} else {
curr = cont.successK(a);
}
}
} catch (error) {
if (isRetryException(error)) {
curr = this.unwindStack(undefined, true);
if (!curr) {
exit = TExit.retry;
}
} else if (isFailException(error)) {
curr = this.unwindStack(error.error, false);
if (!curr) {
exit = TExit.fail(error.error);
}
} else if (isDieException(error)) {
curr = this.unwindStack(error.defect, false);
if (!curr) {
exit = TExit.die(error.defect);
}
} else if (isInterruptException(error)) {
exit = TExit.interrupt(error.fiberId);
} else {
throw error;
}
this.logTrace(curr.trace);
const annotation = new _cause.StackAnnotation(this.stackToLines(), this.execution?.toChunkReversed() || Chunk.empty);
exit = TExit.die(current.defect, annotation);
break;
}
case 8:
{
this.logTrace(curr.trace);
const annotation = new _cause.StackAnnotation(this.stackToLines(), this.execution?.toChunkReversed() || Chunk.empty);
const cont = this.nextFailure();
if (!cont) {
exit = TExit.fail(current.error, annotation);
} else {
this.logTrace(cont.trace);
curr = cont.failK(current.error);
}
break;
}
case 3:
case 7:
{
this.contStack = new _stack.Stack(current, this.contStack);
curr = current.first;
this.logTrace(curr.trace);
const cont = this.nextRetry();
if (!cont) {
exit = TExit.retry;
} else {
this.logTrace(cont.trace);
curr = cont.retryK();
}
break;
}
case 1:
case 10:
{
this.contStack = new _stack.Stack(current, this.contStack);
curr = current.first;
this.logTrace(curr.trace);
const annotation = new _cause.StackAnnotation(this.stackToLines(), this.execution?.toChunkReversed() || Chunk.empty);
exit = TExit.interrupt(this.fiberId, annotation);
break;
}
case 0:
{
this.logTrace(current.trace);
curr = current.evaluate(this);
break;
}
case 3:
case 1:
case 2:
{
this.contStack = new _stack.Stack(current, this.contStack);
this.pushStack(current);
curr = current.first;

@@ -389,6 +488,6 @@ break;

{
this.envStack = new _stack.Stack(current.provide(this.envStack.value), this.envStack);
curr = ensuring(sync(() => {
this.envStack = this.envStack.previous;
}))(current.stm);
this.logTrace(current.trace);
const env = this.env;
this.env = current.provide(env);
curr = ensuring(sync(() => this.env = env))(current.stm);
break;

@@ -398,13 +497,10 @@ }

{
this.logTrace(current.trace);
const value = current.value;
if (!this.contStack) {
const cont = this.nextSuccess();
if (!cont) {
exit = TExit.succeed(value);
} else {
const cont = this.contStack.value;
this.contStack = this.contStack.previous;
if (cont.opSTM === 1 || cont.opSTM === 2) {
curr = succeed(value);
} else {
curr = cont.successK(value);
}
this.logTrace(cont.trace);
curr = cont.successK(value);
}

@@ -415,13 +511,10 @@ break;

{
this.logTrace(current.trace);
const value = current.evaluate();
if (!this.contStack) {
const cont = this.nextSuccess();
if (!cont) {
exit = TExit.succeed(value);
} else {
const cont = this.contStack.value;
this.contStack = this.contStack.previous;
if (cont.opSTM === 1 || cont.opSTM === 2) {
curr = succeed(value);
} else {
curr = cont.successK(value);
}
this.logTrace(cont.trace);
curr = cont.successK(value);
}

@@ -431,3 +524,4 @@ break;

}
opCount = opCount + 1;
} catch (e) {
curr = die(e);
}

@@ -456,11 +550,14 @@ }

{
return completeTodos(Exit.fail(tExit.error), journal, scheduler);
const cause = Cause.fail(tExit.error);
return completeTodos(Exit.failCause(tExit.annotation.stack.length > 0 || tExit.annotation.execution.length > 0 ? Cause.annotated(cause, tExit.annotation) : cause), journal, scheduler);
}
case 1:
{
return completeTodos(Exit.die(tExit.defect), journal, scheduler);
const cause = Cause.die(tExit.defect);
return completeTodos(Exit.failCause(tExit.annotation.stack.length > 0 || tExit.annotation.execution.length > 0 ? Cause.annotated(cause, tExit.annotation) : cause), journal, scheduler);
}
case 2:
{
return completeTodos(Exit.interrupt(fiberId), journal, scheduler);
const cause = Cause.interrupt(fiberId);
return completeTodos(Exit.failCause(tExit.annotation.stack.length > 0 || tExit.annotation.execution.length > 0 ? Cause.annotated(cause, tExit.annotation) : cause), journal, scheduler);
}

@@ -489,11 +586,14 @@ case 4:

{
return completeTodos(Exit.fail(tExit.error), journal, scheduler);
const cause = Cause.fail(tExit.error);
return completeTodos(Exit.failCause(tExit.annotation.stack.length > 0 || tExit.annotation.execution.length > 0 ? Cause.annotated(cause, tExit.annotation) : cause), journal, scheduler);
}
case 1:
{
return completeTodos(Exit.die(tExit.defect), journal, scheduler);
const cause = Cause.die(tExit.defect);
return completeTodos(Exit.failCause(tExit.annotation.stack.length > 0 || tExit.annotation.execution.length > 0 ? Cause.annotated(cause, tExit.annotation) : cause), journal, scheduler);
}
case 2:
{
return completeTodos(Exit.interrupt(fiberId), journal, scheduler);
const cause = Cause.interrupt(fiberId);
return completeTodos(Exit.failCause(tExit.annotation.stack.length > 0 || tExit.annotation.execution.length > 0 ? Cause.annotated(cause, tExit.annotation) : cause), journal, scheduler);
}

@@ -506,24 +606,18 @@ case 4:

};
const tryCommitAsync = (journal, fiberId, stm, txnId, state, context, scheduler) => {
return k => {
if (STMState.isRunning(MutableRef.get(state))) {
if (journal == null) {
const result = tryCommit(fiberId, stm, state, context, scheduler);
switch (result.op) {
case 0:
{
completeTryCommit(result.exit, k);
break;
}
case 1:
{
suspendTryCommit(fiberId, stm, txnId, state, context, k, result.journal, result.journal, scheduler);
break;
}
const tryCommitAsync = (fiberId, self, txnId, state, context, scheduler, k) => {
if (STMState.isRunning(MutableRef.get(state))) {
const result = tryCommit(fiberId, self, state, context, scheduler);
switch (result.op) {
case 0:
{
completeTryCommit(result.exit, k);
break;
}
} else {
suspendTryCommit(fiberId, stm, txnId, state, context, k, journal, journal, scheduler);
}
case 1:
{
Journal.addTodo(txnId, result.journal, () => tryCommitAsync(fiberId, self, txnId, state, context, scheduler, k));
break;
}
}
};
}
};

@@ -540,31 +634,2 @@ const completeTodos = (exit, journal, scheduler) => {

};
const suspendTryCommit = (fiberId, stm, txnId, state, context, k, accum, journal, scheduler) => {
// eslint-disable-next-line no-constant-condition
while (1) {
Journal.addTodo(txnId, journal, () => tryCommitAsync(undefined, fiberId, stm, txnId, state, context, scheduler)(k));
if (Journal.isInvalid(journal)) {
const result = tryCommit(fiberId, stm, state, context, scheduler);
switch (result.op) {
case 0:
{
completeTryCommit(result.exit, k);
return;
}
case 1:
{
const untracked = Journal.untrackedTodoTargets(accum, result.journal);
if (untracked.size > 0) {
for (const entry of untracked) {
accum.set(entry[0], entry[1]);
}
journal = untracked;
}
break;
}
}
} else {
return;
}
}
};
//# sourceMappingURL=stm.js.map

@@ -67,6 +67,7 @@ "use strict";

exports.isRetry = isRetry;
const fail = error => ({
const fail = (error, annotation) => ({
[ExitTypeId]: variance,
op: OP_FAIL,
error,
annotation,
[Equal.symbolHash]() {

@@ -81,6 +82,7 @@ return Equal.hashCombine(Equal.hash(error))(Equal.hashCombine(Equal.hash(OP_FAIL))(Equal.hash(TExitSymbolKey)));

exports.fail = fail;
const die = defect => ({
const die = (defect, annotation) => ({
[ExitTypeId]: variance,
op: OP_DIE,
defect,
annotation,
[Equal.symbolHash]() {

@@ -95,6 +97,7 @@ return Equal.hashCombine(Equal.hash(defect))(Equal.hashCombine(Equal.hash(OP_DIE))(Equal.hash(TExitSymbolKey)));

exports.die = die;
const interrupt = fiberId => ({
const interrupt = (fiberId, annotation) => ({
[ExitTypeId]: variance,
op: OP_INTERRUPT,
fiberId,
annotation,
[Equal.symbolHash]() {

@@ -101,0 +104,0 @@ return Equal.hashCombine(Equal.hash(fiberId))(Equal.hashCombine(Equal.hash(OP_INTERRUPT))(Equal.hash(TExitSymbolKey)));

@@ -6,3 +6,3 @@ "use strict";

});
exports.untrackedTodoTargets = exports.prepareResetJournal = exports.isValid = exports.isInvalid = exports.execTodos = exports.commitJournal = exports.collectTodos = exports.analyzeJournal = exports.addTodo = exports.JournalAnalysisReadWrite = exports.JournalAnalysisReadOnly = exports.JournalAnalysisInvalid = void 0;
exports.isValid = exports.isInvalid = exports.execTodos = exports.commitJournal = exports.collectTodos = exports.analyzeJournal = exports.addTodo = exports.JournalAnalysisReadWrite = exports.JournalAnalysisReadOnly = exports.JournalAnalysisInvalid = void 0;
var Entry = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/io/internal/stm/entry"));

@@ -21,16 +21,2 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

exports.JournalAnalysisReadOnly = JournalAnalysisReadOnly;
const prepareResetJournal = journal => {
const saved = new Map();
for (const entry of journal) {
saved.set(entry[0], Entry.copy(entry[1]));
}
return () => {
journal.clear();
for (const entry of saved) {
journal.set(entry[0], entry[1]);
}
};
};
/** @internal */
exports.prepareResetJournal = prepareResetJournal;
const commitJournal = journal => {

@@ -75,5 +61,5 @@ for (const entry of journal) {

const execTodos = todos => {
const todoKeys = Array.from(todos.keys()).sort();
for (const todo of todoKeys) {
todos.get(todo)[1]();
const todosSorted = Array.from(todos.entries()).sort((x, y) => x[0] - y[0]);
for (const [_, todo] of todosSorted) {
todo();
}

@@ -95,20 +81,2 @@ };

exports.addTodo = addTodo;
const untrackedTodoTargets = (oldJournal, newJournal) => {
const untracked = new Map();
for (const [ref, entry] of newJournal) {
if (
// We already tracked this one
!oldJournal.has(ref) &&
// This `TRef` was created in the current transaction, so no need to
// add any todos to it, because it cannot be modified from the outside
// until the transaction succeeds; so any todo added to it would never
// succeed.
!entry.isNew) {
untracked.set(ref, entry);
}
}
return untracked;
};
/** @internal */
exports.untrackedTodoTargets = untrackedTodoTargets;
const isValid = journal => {

@@ -115,0 +83,0 @@ let valid = true;

@@ -27,14 +27,53 @@ import * as internal from "@effect/io/internal/stm";

}
export declare const make: <A>(evaluate: () => A) => internal.STM<never, never, Ref<A>>;
/**
* @macro traced
*/
export declare const make: <A>(value: A) => internal.STM<never, never, Ref<A>>;
/**
* @macro traced
*/
export declare const get: <A>(self: Ref<A>) => internal.STM<never, never, A>;
/**
* @macro traced
*/
export declare const set: <A>(value: A) => (self: Ref<A>) => internal.STM<never, never, void>;
/**
* @macro traced
*/
export declare const getAndSet: <A>(value: A) => (self: Ref<A>) => internal.STM<never, never, A>;
/**
* @macro traced
*/
export declare const getAndUpdate: <A>(f: (a: A) => A) => (self: Ref<A>) => internal.STM<never, never, A>;
/**
* @macro traced
*/
export declare const getAndUpdateSome: <A>(f: (a: A) => Option.Option<A>) => (self: Ref<A>) => internal.STM<never, never, A>;
/**
* @macro traced
*/
export declare const setAndGet: <A>(value: A) => (self: Ref<A>) => internal.STM<never, never, A>;
/**
* @macro traced
*/
export declare const modify: <A, B>(f: (a: A) => readonly [B, A]) => (self: Ref<A>) => internal.STM<never, never, B>;
/**
* @macro traced
*/
export declare const modifySome: <A, B>(fallback: B, f: (a: A) => Option.Option<readonly [B, A]>) => (self: Ref<A>) => internal.STM<never, never, B>;
/**
* @macro traced
*/
export declare const update: <A>(f: (a: A) => A) => (self: Ref<A>) => internal.STM<never, never, void>;
/**
* @macro traced
*/
export declare const updateAndGet: <A>(f: (a: A) => A) => (self: Ref<A>) => internal.STM<never, never, A>;
/**
* @macro traced
*/
export declare const updateSome: <A>(f: (a: A) => Option.Option<A>) => (self: Ref<A>) => internal.STM<never, never, void>;
/**
* @macro traced
*/
export declare const updateSomeAndGet: <A>(f: (a: A) => Option.Option<A>) => (self: Ref<A>) => internal.STM<never, never, A>;

@@ -41,0 +80,0 @@ export declare const unsafeGet: (journal: Journal.Journal) => <A>(self: Ref<A>) => A;

@@ -7,2 +7,3 @@ "use strict";

exports.updateSomeAndGet = exports.updateSome = exports.updateAndGet = exports.update = exports.unsafeSet = exports.unsafeGet = exports.setAndGet = exports.set = exports.modifySome = exports.modify = exports.make = exports.getAndUpdateSome = exports.getAndUpdate = exports.getAndSet = exports.get = exports.RefTypeId = exports.RefImpl = void 0;
var _Debug = /*#__PURE__*/require("@effect/io/Debug");
var internal = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/io/internal/stm"));

@@ -28,7 +29,7 @@ var Entry = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/io/internal/stm/entry"));

modify(f) {
return internal.effect(journal => {
const entry = getOrMakeEntry(this, journal);
return internal.withSTMRuntime(_ => {
const entry = getOrMakeEntry(this, _.journal);
const [retValue, newValue] = f(Entry.unsafeGet(entry));
Entry.unsafeSet(entry, newValue);
return retValue;
return internal.succeed(retValue);
});

@@ -39,37 +40,112 @@ }

_a = RefTypeId;
const make = evaluate => {
return internal.effect(journal => {
const value = evaluate();
/**
* @macro traced
*/
const make = value => {
const trace = (0, _Debug.getCallTrace)();
return internal.withSTMRuntime(_ => {
const ref = new RefImpl(value);
journal.set(ref, Entry.make(ref, true));
return ref;
});
_.journal.set(ref, Entry.make(ref, true));
return internal.succeed(ref);
}).traced(trace);
};
/**
* @macro traced
*/
exports.make = make;
const get = self => self.modify(a => [a, a]);
const get = self => {
const trace = (0, _Debug.getCallTrace)();
return self.modify(a => [a, a]).traced(trace);
};
/**
* @macro traced
*/
exports.get = get;
const set = value => self => self.modify(() => [void 0, value]);
const set = value => self => {
const trace = (0, _Debug.getCallTrace)();
return self.modify(() => [void 0, value]).traced(trace);
};
/**
* @macro traced
*/
exports.set = set;
const getAndSet = value => self => self.modify(a => [a, value]);
const getAndSet = value => self => {
const trace = (0, _Debug.getCallTrace)();
return self.modify(a => [a, value]).traced(trace);
};
/**
* @macro traced
*/
exports.getAndSet = getAndSet;
const getAndUpdate = f => self => self.modify(a => [a, f(a)]);
const getAndUpdate = f => self => {
const trace = (0, _Debug.getCallTrace)();
return self.modify(a => [a, f(a)]).traced(trace);
};
/**
* @macro traced
*/
exports.getAndUpdate = getAndUpdate;
const getAndUpdateSome = f => self => self.modify(a => Option.match(() => [a, a], b => [a, b])(f(a)));
const getAndUpdateSome = f => {
const trace = (0, _Debug.getCallTrace)();
return self => self.modify(a => Option.match(() => [a, a], b => [a, b])(f(a))).traced(trace);
};
/**
* @macro traced
*/
exports.getAndUpdateSome = getAndUpdateSome;
const setAndGet = value => self => self.modify(() => [value, value]);
const setAndGet = value => self => {
const trace = (0, _Debug.getCallTrace)();
return self.modify(() => [value, value]).traced(trace);
};
/**
* @macro traced
*/
exports.setAndGet = setAndGet;
const modify = f => self => self.modify(f);
const modify = f => {
const trace = (0, _Debug.getCallTrace)();
return self => self.modify(f).traced(trace);
};
/**
* @macro traced
*/
exports.modify = modify;
const modifySome = (fallback, f) => self => self.modify(a => Option.match(() => [fallback, a], b => b)(f(a)));
const modifySome = (fallback, f) => {
const trace = (0, _Debug.getCallTrace)();
return self => self.modify(a => Option.match(() => [fallback, a], b => b)(f(a))).traced(trace);
};
/**
* @macro traced
*/
exports.modifySome = modifySome;
const update = f => self => self.modify(a => [void 0, f(a)]);
const update = f => {
const trace = (0, _Debug.getCallTrace)();
return self => self.modify(a => [void 0, f(a)]).traced(trace);
};
/**
* @macro traced
*/
exports.update = update;
const updateAndGet = f => self => self.modify(a => {
const b = f(a);
return [b, b];
});
const updateAndGet = f => {
const trace = (0, _Debug.getCallTrace)();
return self => self.modify(a => {
const b = f(a);
return [b, b];
}).traced(trace);
};
/**
* @macro traced
*/
exports.updateAndGet = updateAndGet;
const updateSome = f => self => self.modify(a => [void 0, Option.match(() => a, b => b)(f(a))]);
const updateSome = f => {
const trace = (0, _Debug.getCallTrace)();
return self => self.modify(a => [void 0, Option.match(() => a, b => b)(f(a))]).traced(trace);
};
/**
* @macro traced
*/
exports.updateSome = updateSome;
const updateSomeAndGet = f => self => self.modify(a => Option.match(() => [a, a], b => [b, b])(f(a)));
const updateSomeAndGet = f => {
const trace = (0, _Debug.getCallTrace)();
return self => self.modify(a => Option.match(() => [a, a], b => [b, b])(f(a))).traced(trace);
};
exports.updateSomeAndGet = updateSomeAndGet;

@@ -76,0 +152,0 @@ const getOrMakeEntry = (self, journal) => {

{
"name": "@effect/io",
"version": "0.0.28",
"version": "0.0.29",
"license": "MIT",

@@ -10,5 +10,5 @@ "repository": {

"dependencies": {
"@effect/printer": "^0.1.6",
"@effect/printer": "^0.1.7",
"@fp-ts/core": "^0.0.9",
"@fp-ts/data": "^0.0.18"
"@fp-ts/data": "^0.0.19"
},

@@ -15,0 +15,0 @@ "publishConfig": {

@@ -778,31 +778,43 @@ import * as Cause from "@effect/io/Cause"

/**
* @macro traced
*/
export const acquireN = (n: number) => {
const trace = getCallTrace()
return (self: Semaphore): STM.STM<never, never, void> => {
return STM.effect((journal) => {
return STM.withSTMRuntime((_) => {
if (n < 0) {
throw Cause.IllegalArgumentException(`Unexpected negative value ${n} passed to Semaphore.acquireN`)
}
const value = pipe(self.permits, TRef.unsafeGet(journal))
const value = pipe(self.permits, TRef.unsafeGet(_.journal))
if (value < n) {
throw new STM.STMRetryException()
return STM.retry()
} else {
return pipe(self.permits, TRef.unsafeSet(value - n, journal))
return STM.succeed(pipe(self.permits, TRef.unsafeSet(value - n, _.journal)))
}
})
}).traced(trace)
}
}
/**
* @macro traced
*/
export const releaseN = (n: number) => {
const trace = getCallTrace()
return (self: Semaphore): STM.STM<never, never, void> => {
return STM.effect((journal) => {
return STM.withSTMRuntime((_) => {
if (n < 0) {
throw Cause.IllegalArgumentException(`Unexpected negative value ${n} passed to Semaphore.releaseN`)
}
const current = pipe(self.permits, TRef.unsafeGet(journal))
return pipe(self.permits, TRef.unsafeSet(current + n, journal))
})
const current = pipe(self.permits, TRef.unsafeGet(_.journal))
return STM.succeed(pipe(self.permits, TRef.unsafeSet(current + n, _.journal)))
}).traced(trace)
}
}
/**
* @macro traced
*/
export const withPermits = (permits: number) => {
const trace = getCallTrace()
return (semaphore: Semaphore) => {

@@ -820,3 +832,3 @@ return <R, E, A>(self: Effect.Effect<R, E, A>): Effect.Effect<R, E, A> => {

)
)
).traced(trace)
}

@@ -826,3 +838,7 @@ }

/**
* @macro traced
*/
export const withPermitsScoped = (permits: number) => {
const trace = getCallTrace()
return (self: Semaphore): Effect.Effect<Scope.Scope, never, void> =>

@@ -832,3 +848,3 @@ acquireReleaseInterruptible(

() => pipe(self, releaseN(permits), STM.commit)
)
).traced(trace)
}

@@ -835,0 +851,0 @@

/** @internal */
export const OP_EFFECT = 0 as const
export const OP_WITH_STM_RUNTIME = 0 as const
/** @internal */
export type OP_EFFECT = typeof OP_EFFECT
export type OP_WITH_STM_RUNTIME = typeof OP_WITH_STM_RUNTIME

@@ -32,11 +32,35 @@ /** @internal */

/** @internal */
export const OP_SUCCEED = 5 as const
export const OP_SYNC = 5 as const
/** @internal */
export type OP_SYNC = typeof OP_SYNC
/** @internal */
export const OP_SUCCEED = 6 as const
/** @internal */
export type OP_SUCCEED = typeof OP_SUCCEED
/** @internal */
export const OP_SUCCEED_NOW = 6 as const
export const OP_RETRY = 7 as const
/** @internal */
export type OP_SUCCEED_NOW = typeof OP_SUCCEED_NOW
export type OP_RETRY = typeof OP_RETRY
/** @internal */
export const OP_FAIL = 8 as const
/** @internal */
export type OP_FAIL = typeof OP_FAIL
/** @internal */
export const OP_DIE = 9 as const
/** @internal */
export type OP_DIE = typeof OP_DIE
/** @internal */
export const OP_INTERRUPT = 10 as const
/** @internal */
export type OP_INTERRUPT = typeof OP_INTERRUPT

@@ -0,1 +1,2 @@

import { getCallTrace } from "@effect/io/Debug"
import type * as Effect from "@effect/io/Effect"

@@ -8,29 +9,53 @@ import * as circular from "@effect/io/internal/effect/circular"

/**
* @macro traced
*/
export const make = (permits: number): STM.STM<never, never, circular.Semaphore> => {
const trace = getCallTrace()
return pipe(
Ref.make(() => permits),
Ref.make(permits),
STM.map((permits) => new circular.SemaphoreImpl(permits))
)
).traced(trace)
}
/**
* @macro traced
*/
export function available(self: circular.Semaphore): STM.STM<never, never, number> {
return Ref.get(self.permits)
const trace = getCallTrace()
return Ref.get(self.permits).traced(trace)
}
/**
* @macro traced
*/
export const acquire = (self: circular.Semaphore): STM.STM<never, never, void> => {
return pipe(self, circular.acquireN(1))
const trace = getCallTrace()
return pipe(self, circular.acquireN(1)).traced(trace)
}
/**
* @macro traced
*/
export const release = (self: circular.Semaphore): STM.STM<never, never, void> => {
return pipe(self, circular.releaseN(1))
const trace = getCallTrace()
return pipe(self, circular.releaseN(1)).traced(trace)
}
/**
* @macro traced
*/
export const withPermit = (semaphore: circular.Semaphore) => {
const trace = getCallTrace()
return <R, E, A>(self: Effect.Effect<R, E, A>): Effect.Effect<R, E, A> => {
return pipe(self, circular.withPermits(1)(semaphore))
return pipe(self, circular.withPermits(1)(semaphore)).traced(trace)
}
}
/**
* @macro traced
*/
export const withPermitScoped = (self: circular.Semaphore): Effect.Effect<Scope.Scope, never, void> => {
return pipe(self, circular.withPermitsScoped(1))
const trace = getCallTrace()
return pipe(self, circular.withPermitsScoped(1)).traced(trace)
}

@@ -1,5 +0,7 @@

import { getCallTrace } from "@effect/io/Debug"
import * as Cause from "@effect/io/Cause"
import { getCallTrace, isTraceEnabled, runtimeDebug } from "@effect/io/Debug"
import type * as Effect from "@effect/io/Effect"
import * as Exit from "@effect/io/Exit"
import type * as FiberId from "@effect/io/Fiber/Id"
import { StackAnnotation } from "@effect/io/internal/cause"
import * as core from "@effect/io/internal/core"

@@ -10,3 +12,2 @@ import * as EffectOpCodes from "@effect/io/internal/opCodes/effect"

import { Stack } from "@effect/io/internal/stack"
import * as Entry from "@effect/io/internal/stm/entry"
import * as TExit from "@effect/io/internal/stm/exit"

@@ -17,2 +18,4 @@ import * as Journal from "@effect/io/internal/stm/journal"

import * as TxnId from "@effect/io/internal/stm/txnId"
import { RingBuffer } from "@effect/io/internal/support"
import * as Chunk from "@fp-ts/data/Chunk"
import type * as Context from "@fp-ts/data/Context"

@@ -28,3 +31,10 @@ import * as Either from "@fp-ts/data/Either"

export interface STM<R, E, A> extends STM.Variance<R, E, A>, Effect.Effect<R, E, A> {}
export interface STM<R, E, A> extends STM.Variance<R, E, A>, Effect.Effect<R, E, A> {
/** @internal */
trace: string | undefined
/** @internal */
traced(trace: string | undefined): STM<R, E, A>
/** @internal */
commit(): Effect.Effect<R, E, A>
}

@@ -47,4 +57,8 @@ export declare namespace STM {

| STMProvide
| STMSync
| STMSucceed
| STMSucceedNow
| STMRetry
| STMFail
| STMDie
| STMInterrupt

@@ -57,5 +71,84 @@ const stmVariance = {

const proto = Object.assign({}, core.proto, {
/**
* @macro traced
*/
export const commit = <R, E, A>(self: STM<R, E, A>): Effect.Effect<R, E, A> => {
const trace = getCallTrace()
return core.withFiberRuntime<R, E, A>((state) => {
const fiberId = state.id()
const env = state.getFiberRef(core.currentEnvironment) as Context.Context<R>
const scheduler = state.getFiberRef(core.currentScheduler)
const commitResult = tryCommitSync(fiberId, self, env, scheduler)
switch (commitResult.op) {
case TryCommit.OP_DONE: {
return core.done(commitResult.exit)
}
case TryCommit.OP_SUSPEND: {
const txnId = TxnId.make()
const state = MutableRef.make<STMState.STMState<E, A>>(STMState.running)
const io = core.async(
(k: (effect: Effect.Effect<R, E, A>) => unknown): void => {
if (STMState.isRunning(MutableRef.get(state))) {
if (Journal.isInvalid(commitResult.journal)) {
const result = tryCommit(fiberId, self, state, env, scheduler)
switch (result.op) {
case TryCommit.OP_DONE: {
completeTryCommit(result.exit, k)
break
}
case TryCommit.OP_SUSPEND: {
Journal.addTodo(
txnId,
result.journal,
() => tryCommitAsync(fiberId, self, txnId, state, env, scheduler, k)
)
break
}
}
} else {
Journal.addTodo(
txnId,
commitResult.journal,
() => tryCommitAsync(fiberId, self, txnId, state, env, scheduler, k)
)
}
}
}
)
return core.uninterruptibleMask((restore) =>
pipe(
restore(io),
core.catchAllCause((cause) => {
let currentState = MutableRef.get(state)
if (Equal.equals(currentState, STMState.running)) {
pipe(state, MutableRef.set(STMState.interrupted as STMState.STMState<E, A>))
}
currentState = MutableRef.get(state)
return currentState.op === STMState.OP_DONE
? core.done(currentState.exit)
: core.failCause(cause)
})
)
)
}
}
}).traced(trace)
}
const proto = Object.assign({}, {
...core.proto,
[STMTypeId]: stmVariance,
op: EffectOpCodes.OP_COMMIT
op: EffectOpCodes.OP_COMMIT,
commit(this: STM<any, any, any>): Effect.Effect<any, any, any> {
return commit(this)
},
traced(this: STM<any, any, any>, trace: string | undefined): STM<any, any, any> {
if (!isTraceEnabled() || trace === this["trace"]) {
return this
}
const fresh = Object.create(proto)
Object.assign(fresh, this)
fresh.trace = trace
return fresh
}
})

@@ -69,8 +162,6 @@

interface STMEffect extends
STMOp<STMOpCodes.OP_EFFECT, {
STMOp<STMOpCodes.OP_WITH_STM_RUNTIME, {
readonly evaluate: (
journal: Journal.Journal,
fiberId: FiberId.FiberId,
context: Context.Context<unknown>
) => unknown
runtime: STMDriver<unknown, unknown, unknown>
) => STM<unknown, unknown, unknown>
}>

@@ -88,3 +179,2 @@ {}

STMOp<STMOpCodes.OP_ON_RETRY, {
readonly opSTM: STMOpCodes.OP_ON_RETRY
readonly first: STM<unknown, unknown, unknown>

@@ -109,5 +199,4 @@ readonly retryK: () => STM<unknown, unknown, unknown>

interface STMSucceed extends
STMOp<STMOpCodes.OP_SUCCEED, {
readonly opSTM: STMOpCodes.OP_SUCCEED
interface STMSync extends
STMOp<STMOpCodes.OP_SYNC, {
readonly evaluate: () => unknown

@@ -117,5 +206,4 @@ }>

interface STMSucceedNow extends
STMOp<STMOpCodes.OP_SUCCEED_NOW, {
readonly opSTM: STMOpCodes.OP_SUCCEED_NOW
interface STMSucceed extends
STMOp<STMOpCodes.OP_SUCCEED, {
readonly value: unknown

@@ -125,77 +213,27 @@ }>

export const STMFailExceptionTypeId = Symbol.for("@effect/stm/STM/FailException")
interface STMRetry extends STMOp<STMOpCodes.OP_RETRY, {}> {}
export type STMFailExceptionTypeId = typeof STMFailExceptionTypeId
interface STMFail extends
STMOp<STMOpCodes.OP_FAIL, {
readonly error: unknown
}>
{}
export interface STMFailException<E> {
readonly [STMFailExceptionTypeId]: STMFailExceptionTypeId
readonly error: E
}
interface STMDie extends
STMOp<STMOpCodes.OP_DIE, {
readonly defect: unknown
}>
{}
export class STMFailException<E> implements STMFailException<E> {
readonly [STMFailExceptionTypeId]: STMFailExceptionTypeId = STMFailExceptionTypeId
constructor(readonly error: E) {}
}
interface STMInterrupt extends STMOp<STMOpCodes.OP_INTERRUPT, {}> {}
export const isFailException = (u: unknown): u is STMFailException<unknown> => {
return typeof u === "object" && u != null && STMFailExceptionTypeId in u
}
export const STMDieExceptionTypeId = Symbol.for("@effect/stm/STM/DieException")
export type STMDieExceptionTypeId = typeof STMDieExceptionTypeId
export interface STMDieException {
readonly [STMDieExceptionTypeId]: STMDieExceptionTypeId
readonly defect: unknown
}
export class STMDieException implements STMDieException {
readonly [STMDieExceptionTypeId]: STMDieExceptionTypeId = STMDieExceptionTypeId
constructor(readonly defect: unknown) {}
}
export const isDieException = (u: unknown): u is STMDieException => {
return typeof u === "object" && u != null && STMDieExceptionTypeId in u
}
export const STMInterruptExceptionTypeId = Symbol.for("@effect/stm/STM/InterruptException")
export type STMInterruptExceptionTypeId = typeof STMInterruptExceptionTypeId
export interface STMInterruptException {
readonly [STMInterruptExceptionTypeId]: STMInterruptExceptionTypeId
readonly fiberId: FiberId.FiberId
}
export class STMInterruptException implements STMInterruptException {
readonly [STMInterruptExceptionTypeId]: STMInterruptExceptionTypeId = STMInterruptExceptionTypeId
constructor(readonly fiberId: FiberId.FiberId) {}
}
export const isInterruptException = (u: unknown): u is STMInterruptException => {
return typeof u === "object" && u != null && STMInterruptExceptionTypeId in u
}
export const STMRetryExceptionTypeId = Symbol.for("@effect/stm/STM/RetryException")
export type STMRetryExceptionTypeId = typeof STMRetryExceptionTypeId
export interface STMRetryException {
readonly [STMRetryExceptionTypeId]: STMRetryExceptionTypeId
}
export class STMRetryException {
readonly [STMRetryExceptionTypeId]: STMRetryExceptionTypeId = STMRetryExceptionTypeId
}
export const isRetryException = (u: unknown): u is STMRetryException => {
return typeof u === "object" && u != null && STMRetryExceptionTypeId in u
}
export function effect<R, A>(
f: (journal: Journal.Journal, fiberId: FiberId.FiberId, context: Context.Context<R>) => A
): STM<R, never, A> {
/**
* @macro traced
*/
export function withSTMRuntime<R, E, A>(
f: (runtime: STMDriver<unknown, unknown, unknown>) => STM<R, E, A>
): STM<R, E, A> {
const trace = getCallTrace()
const stm = Object.create(proto)
stm.opSTM = STMOpCodes.OP_EFFECT
stm.opSTM = STMOpCodes.OP_WITH_STM_RUNTIME
stm.evaluate = f

@@ -206,30 +244,58 @@ stm.trace = trace

/**
* @macro traced
*/
export const fail = <E>(error: E): STM<never, E, never> => {
return effect(() => {
throw new STMFailException(error)
})
const trace = getCallTrace()
const stm = Object.create(proto)
stm.opSTM = STMOpCodes.OP_FAIL
stm.error = error
stm.trace = trace
return stm
}
/**
* @macro traced
*/
export const die = (defect: unknown): STM<never, never, never> => {
return effect(() => {
throw new STMDieException(defect)
})
const trace = getCallTrace()
const stm = Object.create(proto)
stm.opSTM = STMOpCodes.OP_DIE
stm.defect = defect
stm.trace = trace
return stm
}
/**
* @macro traced
*/
export const interrupt = (): STM<never, never, never> => {
return effect((_, fiberId) => {
throw new STMInterruptException(fiberId)
const trace = getCallTrace()
return withSTMRuntime((_) => {
const stm = Object.create(proto)
stm.opSTM = STMOpCodes.OP_INTERRUPT
stm.trace = trace
stm.fiberId = _.fiberId
return stm
})
}
/**
* @macro traced
*/
export const retry = (): STM<never, never, never> => {
return effect(() => {
throw new STMRetryException()
})
const trace = getCallTrace()
const stm = Object.create(proto)
stm.opSTM = STMOpCodes.OP_RETRY
stm.trace = trace
return stm
}
/**
* @macro traced
*/
export const succeed = <A>(value: A): STM<never, never, A> => {
const trace = getCallTrace()
const stm = Object.create(proto)
stm.opSTM = STMOpCodes.OP_SUCCEED_NOW
stm.opSTM = STMOpCodes.OP_SUCCEED
stm.value = value

@@ -240,6 +306,9 @@ stm.trace = trace

/**
* @macro traced
*/
export const sync = <A>(evaluate: () => A): STM<never, never, A> => {
const trace = getCallTrace()
const stm = Object.create(proto)
stm.opSTM = STMOpCodes.OP_SUCCEED
stm.opSTM = STMOpCodes.OP_SYNC
stm.evaluate = evaluate

@@ -250,2 +319,5 @@ stm.trace = trace

/**
* @macro traced
*/
export const catchAll = <E, R1, E1, B>(f: (e: E) => STM<R1, E1, B>) => {

@@ -263,2 +335,5 @@ const trace = getCallTrace()

/**
* @macro traced
*/
export const orTry = <R1, E1, A1>(that: () => STM<R1, E1, A1>) => {

@@ -276,2 +351,5 @@ const trace = getCallTrace()

/**
* @macro traced
*/
export const flatMap = <A, R1, E1, A2>(f: (a: A) => STM<R1, E1, A2>) => {

@@ -289,2 +367,5 @@ const trace = getCallTrace()

/**
* @macro traced
*/
export const provideSomeEnvironment = <R0, R>(f: (context: Context.Context<R0>) => Context.Context<R>) => {

@@ -302,8 +383,15 @@ const trace = getCallTrace()

/**
* @macro traced
*/
export const map = <A, B>(f: (a: A) => B) => {
const trace = getCallTrace()
return <R, E>(self: STM<R, E, A>): STM<R, E, B> => {
return pipe(self, flatMap((a) => sync(() => f(a))))
return pipe(self, flatMap((a) => sync(() => f(a)))).traced(trace)
}
}
/**
* @macro traced
*/
export const foldSTM = <E, R1, E1, A1, A, R2, E2, A2>(

@@ -313,2 +401,3 @@ onFailure: (e: E) => STM<R1, E1, A1>,

) => {
const trace = getCallTrace()
return <R>(self: STM<R, E, A>): STM<R | R1 | R2, E1 | E2, A1 | A2> => {

@@ -329,7 +418,11 @@ return pipe(

})
)
).traced(trace)
}
}
/**
* @macro traced
*/
export const ensuring = <R1, B>(finalizer: STM<R1, never, B>) => {
const trace = getCallTrace()
return <R, E, A>(self: STM<R, E, A>): STM<R | R1, E, A> =>

@@ -342,71 +435,52 @@ pipe(

)
)
).traced(trace)
}
/**
* @macro traced
*/
export const zip = <R1, E1, A1>(that: STM<R1, E1, A1>) => {
const trace = getCallTrace()
return <R, E, A>(self: STM<R, E, A>): STM<R | R1, E | E1, readonly [A, A1]> => {
return pipe(self, zipWith(that, (a, a1) => [a, a1]))
return pipe(self, zipWith(that, (a, a1) => [a, a1] as const)).traced(trace)
}
}
/**
* @macro traced
*/
export const zipLeft = <R1, E1, A1>(that: STM<R1, E1, A1>) => {
const trace = getCallTrace()
return <R, E, A>(self: STM<R, E, A>): STM<R | R1, E | E1, A> => {
return pipe(self, flatMap((a) => pipe(that, map(() => a))))
return pipe(self, flatMap((a) => pipe(that, map(() => a)))).traced(trace)
}
}
/**
* @macro traced
*/
export const zipRight = <R1, E1, A1>(that: STM<R1, E1, A1>) => {
const trace = getCallTrace()
return <R, E, A>(self: STM<R, E, A>): STM<R | R1, E | E1, A1> => {
return pipe(self, flatMap(() => that))
return pipe(self, flatMap(() => that)).traced(trace)
}
}
/**
* @macro traced
*/
export const zipWith = <R1, E1, A1, A, A2>(that: STM<R1, E1, A1>, f: (a: A, b: A1) => A2) => {
const trace = getCallTrace()
return <R, E>(self: STM<R, E, A>): STM<R1 | R, E | E1, A2> => {
return pipe(self, flatMap((a) => pipe(that, map((b) => f(a, b)))))
return pipe(self, flatMap((a) => pipe(that, map((b) => f(a, b))))).traced(trace)
}
}
export const commit = <R, E, A>(self: STM<R, E, A>): Effect.Effect<R, E, A> => {
return core.withFiberRuntime((state) => {
const fiberId = state.id()
const env = state.getFiberRef(core.currentEnvironment) as Context.Context<R>
const scheduler = state.getFiberRef(core.currentScheduler)
const commitResult = tryCommitSync(fiberId, self, env, scheduler)
switch (commitResult.op) {
case TryCommit.OP_DONE: {
return core.done(commitResult.exit)
}
case TryCommit.OP_SUSPEND: {
const txnId = TxnId.make()
const state = MutableRef.make<STMState.STMState<E, A>>(STMState.running)
const io = core.async(
tryCommitAsync(commitResult.journal, fiberId, self, txnId, state, env, scheduler)
)
return core.uninterruptibleMask((restore) =>
pipe(
restore(io),
core.catchAllCause((cause) => {
let currentState = MutableRef.get(state)
if (Equal.equals(currentState, STMState.running)) {
pipe(state, MutableRef.set(STMState.interrupted as STMState.STMState<E, A>))
}
currentState = MutableRef.get(state)
return currentState.op === STMState.OP_DONE
? core.done(currentState.exit)
: core.failCause(cause)
})
)
)
}
}
})
}
type Continuation = STMOnFailure | STMOnSuccess | STMOnRetry
export class STMDriver<R, E, A> {
private yieldOpCount = 2048
private contStack: Stack<Continuation> | undefined
private envStack: Stack<Context.Context<unknown>>
private env: Context.Context<unknown>
private execution: RingBuffer<string> | undefined
private tracesInStack = 0

@@ -419,148 +493,179 @@ constructor(

) {
this.envStack = new Stack(r0 as Context.Context<unknown>)
this.env = r0 as Context.Context<unknown>
}
private unwindStack(error: unknown, isRetry: boolean): Primitive | undefined {
let result: Primitive | undefined = undefined
while (this.contStack && result === undefined) {
const cont = this.contStack.value
private logTrace(trace: string | undefined) {
if (trace) {
if (!this.execution) {
this.execution = new RingBuffer<string>(runtimeDebug.traceExecutionLimit)
}
this.execution.push(trace)
}
}
pushStack(cont: Continuation) {
this.contStack = new Stack(cont, this.contStack)
if ("trace" in cont) {
this.tracesInStack++
}
}
popStack() {
if (this.contStack) {
const current = this.contStack
this.contStack = this.contStack.previous
if (cont.opSTM === STMOpCodes.OP_ON_FAILURE) {
if (!isRetry) {
result = cont.failK(error) as Primitive
}
if ("trace" in current.value) {
this.tracesInStack--
}
if (cont.opSTM === STMOpCodes.OP_ON_RETRY) {
if (isRetry) {
result = cont.retryK() as Primitive
return current.value
}
return
}
stackToLines(): Chunk.Chunk<string> {
if (this.tracesInStack === 0) {
return Chunk.empty
}
const lines: Array<string> = []
let current = this.contStack
let last: undefined | string = undefined
let seen = 0
while (current !== undefined && lines.length < runtimeDebug.traceStackLimit && seen < this.tracesInStack) {
switch (current.value.opSTM) {
case STMOpCodes.OP_ON_SUCCESS:
case STMOpCodes.OP_ON_FAILURE:
case STMOpCodes.OP_ON_RETRY: {
if (current.value.trace) {
seen++
if (current.value.trace !== last) {
last = current.value.trace
lines.push(current.value.trace)
}
}
break
}
}
current = current.previous
}
return result
return Chunk.unsafeFromArray(lines)
}
nextSuccess() {
let current = this.popStack()
while (current && current.opSTM !== STMOpCodes.OP_ON_SUCCESS) {
current = this.popStack()
}
return current
}
nextFailure() {
let current = this.popStack()
while (current && current.opSTM !== STMOpCodes.OP_ON_FAILURE) {
current = this.popStack()
}
return current
}
nextRetry() {
let current = this.popStack()
while (current && current.opSTM !== STMOpCodes.OP_ON_RETRY) {
current = this.popStack()
}
return current
}
run(): TExit.Exit<E, A> {
let curr = this.self as Primitive | undefined
let exit: TExit.Exit<unknown, unknown> | undefined = undefined
let opCount = 0
while (exit === undefined && curr !== undefined) {
if (opCount === this.yieldOpCount) {
let valid = true
for (const [, entry] of this.journal) {
valid = Entry.isValid(entry)
}
if (!valid) {
exit = TExit.retry
} else {
opCount = 0
}
} else {
try {
const current = curr
switch (current.opSTM) {
case STMOpCodes.OP_EFFECT: {
try {
const a = current.evaluate(this.journal, this.fiberId, this.envStack.value)
if (!this.contStack) {
exit = TExit.succeed(a)
} else {
const cont = this.contStack.value
this.contStack = this.contStack.previous
if (
cont.opSTM === STMOpCodes.OP_ON_FAILURE ||
cont.opSTM === STMOpCodes.OP_ON_RETRY
) {
curr = succeed(a) as Primitive
} else {
curr = cont.successK(a) as Primitive
}
}
} catch (error) {
if (isRetryException(error)) {
curr = this.unwindStack(undefined, true)
if (!curr) {
exit = TExit.retry
}
} else if (isFailException(error)) {
curr = this.unwindStack(error.error, false)
if (!curr) {
exit = TExit.fail(error.error)
}
} else if (isDieException(error)) {
curr = this.unwindStack(error.defect, false)
if (!curr) {
exit = TExit.die(error.defect)
}
} else if (isInterruptException(error)) {
exit = TExit.interrupt(error.fiberId)
} else {
throw error
}
case STMOpCodes.OP_DIE: {
this.logTrace(curr.trace)
const annotation = new StackAnnotation(
this.stackToLines(),
this.execution?.toChunkReversed() || Chunk.empty
)
exit = TExit.die(current.defect, annotation)
break
}
case STMOpCodes.OP_FAIL: {
this.logTrace(curr.trace)
const annotation = new StackAnnotation(
this.stackToLines(),
this.execution?.toChunkReversed() || Chunk.empty
)
const cont = this.nextFailure()
if (!cont) {
exit = TExit.fail(current.error, annotation)
} else {
this.logTrace(cont.trace)
curr = cont.failK(current.error) as Primitive
}
break
}
case STMOpCodes.OP_ON_SUCCESS: {
this.contStack = new Stack(current, this.contStack)
curr = current.first as Primitive
case STMOpCodes.OP_RETRY: {
this.logTrace(curr.trace)
const cont = this.nextRetry()
if (!cont) {
exit = TExit.retry
} else {
this.logTrace(cont.trace)
curr = cont.retryK() as Primitive
}
break
}
case STMOpCodes.OP_ON_FAILURE: {
this.contStack = new Stack(current, this.contStack)
curr = current.first as Primitive
case STMOpCodes.OP_INTERRUPT: {
this.logTrace(curr.trace)
const annotation = new StackAnnotation(
this.stackToLines(),
this.execution?.toChunkReversed() || Chunk.empty
)
exit = TExit.interrupt(this.fiberId, annotation)
break
}
case STMOpCodes.OP_WITH_STM_RUNTIME: {
this.logTrace(current.trace)
curr = current.evaluate(this) as Primitive
break
}
case STMOpCodes.OP_ON_SUCCESS:
case STMOpCodes.OP_ON_FAILURE:
case STMOpCodes.OP_ON_RETRY: {
this.contStack = new Stack(current, this.contStack)
this.pushStack(current)
curr = current.first as Primitive
break
}
case STMOpCodes.OP_PROVIDE: {
this.envStack = new Stack(current.provide(this.envStack.value), this.envStack)
this.logTrace(current.trace)
const env = this.env
this.env = current.provide(env)
curr = pipe(
current.stm,
ensuring(sync(() => {
this.envStack = this.envStack.previous!
}))
ensuring(sync(() => (this.env = env)))
) as Primitive
break
}
case STMOpCodes.OP_SUCCEED_NOW: {
case STMOpCodes.OP_SUCCEED: {
this.logTrace(current.trace)
const value = current.value
if (!this.contStack) {
const cont = this.nextSuccess()
if (!cont) {
exit = TExit.succeed(value)
} else {
const cont = this.contStack.value
this.contStack = this.contStack.previous
if (
cont.opSTM === STMOpCodes.OP_ON_FAILURE ||
cont.opSTM === STMOpCodes.OP_ON_RETRY
) {
curr = succeed(value) as Primitive
} else {
curr = cont.successK(value) as Primitive
}
this.logTrace(cont.trace)
curr = cont.successK(value) as Primitive
}
break
}
case STMOpCodes.OP_SUCCEED: {
case STMOpCodes.OP_SYNC: {
this.logTrace(current.trace)
const value = current.evaluate()
if (!this.contStack) {
const cont = this.nextSuccess()
if (!cont) {
exit = TExit.succeed(value)
} else {
const cont = this.contStack.value
this.contStack = this.contStack.previous
if (
cont.opSTM === STMOpCodes.OP_ON_FAILURE ||
cont.opSTM === STMOpCodes.OP_ON_RETRY
) {
curr = succeed(value) as Primitive
} else {
curr = cont.successK(value) as Primitive
}
this.logTrace(cont.trace)
curr = cont.successK(value) as Primitive
}

@@ -570,6 +675,6 @@ break

}
opCount = opCount + 1
} catch (e) {
curr = die(e) as Primitive
}
}
return exit as TExit.Exit<E, A>

@@ -602,9 +707,36 @@ }

case TExit.OP_FAIL: {
return completeTodos(Exit.fail(tExit.error), journal, scheduler)
const cause = Cause.fail(tExit.error)
return completeTodos(
Exit.failCause(
tExit.annotation.stack.length > 0 || tExit.annotation.execution.length > 0 ?
Cause.annotated(cause, tExit.annotation) :
cause
),
journal,
scheduler
)
}
case TExit.OP_DIE: {
return completeTodos(Exit.die(tExit.defect), journal, scheduler)
const cause = Cause.die(tExit.defect)
return completeTodos(
Exit.failCause(
tExit.annotation.stack.length > 0 || tExit.annotation.execution.length > 0 ?
Cause.annotated(cause, tExit.annotation) :
cause
),
journal,
scheduler
)
}
case TExit.OP_INTERRUPT: {
return completeTodos(Exit.interrupt(fiberId), journal, scheduler)
const cause = Cause.interrupt(fiberId)
return completeTodos(
Exit.failCause(
tExit.annotation.stack.length > 0 || tExit.annotation.execution.length > 0 ?
Cause.annotated(cause, tExit.annotation) :
cause
),
journal,
scheduler
)
}

@@ -640,9 +772,36 @@ case TExit.OP_RETRY: {

case TExit.OP_FAIL: {
return completeTodos(Exit.fail(tExit.error), journal, scheduler)
const cause = Cause.fail(tExit.error)
return completeTodos(
Exit.failCause(
tExit.annotation.stack.length > 0 || tExit.annotation.execution.length > 0 ?
Cause.annotated(cause, tExit.annotation) :
cause
),
journal,
scheduler
)
}
case TExit.OP_DIE: {
return completeTodos(Exit.die(tExit.defect), journal, scheduler)
const cause = Cause.die(tExit.defect)
return completeTodos(
Exit.failCause(
tExit.annotation.stack.length > 0 || tExit.annotation.execution.length > 0 ?
Cause.annotated(cause, tExit.annotation) :
cause
),
journal,
scheduler
)
}
case TExit.OP_INTERRUPT: {
return completeTodos(Exit.interrupt(fiberId), journal, scheduler)
const cause = Cause.interrupt(fiberId)
return completeTodos(
Exit.failCause(
tExit.annotation.stack.length > 0 || tExit.annotation.execution.length > 0 ?
Cause.annotated(cause, tExit.annotation) :
cause
),
journal,
scheduler
)
}

@@ -656,37 +815,25 @@ case TExit.OP_RETRY: {

const tryCommitAsync = <R, E, A>(
journal: Journal.Journal | undefined,
fiberId: FiberId.FiberId,
stm: STM<R, E, A>,
self: STM<R, E, A>,
txnId: TxnId.TxnId,
state: MutableRef.MutableRef<STMState.STMState<E, A>>,
context: Context.Context<R>,
scheduler: Scheduler.Scheduler
scheduler: Scheduler.Scheduler,
k: (effect: Effect.Effect<R, E, A>) => unknown
) => {
return (k: (effect: Effect.Effect<R, E, A>) => unknown): void => {
if (STMState.isRunning(MutableRef.get(state))) {
if (journal == null) {
const result = tryCommit(fiberId, stm, state, context, scheduler)
switch (result.op) {
case TryCommit.OP_DONE: {
completeTryCommit(result.exit, k)
break
}
case TryCommit.OP_SUSPEND: {
suspendTryCommit(
fiberId,
stm,
txnId,
state,
context,
k,
result.journal,
result.journal,
scheduler
)
break
}
}
} else {
suspendTryCommit(fiberId, stm, txnId, state, context, k, journal, journal, scheduler)
if (STMState.isRunning(MutableRef.get(state))) {
const result = tryCommit(fiberId, self, state, context, scheduler)
switch (result.op) {
case TryCommit.OP_DONE: {
completeTryCommit(result.exit, k)
break
}
case TryCommit.OP_SUSPEND: {
Journal.addTodo(
txnId,
result.journal,
() => tryCommitAsync(fiberId, self, txnId, state, context, scheduler, k)
)
break
}
}

@@ -714,43 +861,1 @@ }

}
const suspendTryCommit = <R, E, A>(
fiberId: FiberId.FiberId,
stm: STM<R, E, A>,
txnId: TxnId.TxnId,
state: MutableRef.MutableRef<STMState.STMState<E, A>>,
context: Context.Context<R>,
k: (effect: Effect.Effect<R, E, A>) => unknown,
accum: Journal.Journal,
journal: Journal.Journal,
scheduler: Scheduler.Scheduler
): void => {
// eslint-disable-next-line no-constant-condition
while (1) {
Journal.addTodo(
txnId,
journal,
() => tryCommitAsync(undefined, fiberId, stm, txnId, state, context, scheduler)(k)
)
if (Journal.isInvalid(journal)) {
const result = tryCommit(fiberId, stm, state, context, scheduler)
switch (result.op) {
case TryCommit.OP_DONE: {
completeTryCommit(result.exit, k)
return
}
case TryCommit.OP_SUSPEND: {
const untracked = Journal.untrackedTodoTargets(accum, result.journal)
if (untracked.size > 0) {
for (const entry of untracked) {
accum.set(entry[0], entry[1])
}
journal = untracked
}
break
}
}
} else {
return
}
}
}
import type * as FiberId from "@effect/io/Fiber/Id"
import type { StackAnnotation } from "@effect/io/internal/cause"
import * as Equal from "@fp-ts/data/Equal"

@@ -65,2 +66,3 @@ import { pipe } from "@fp-ts/data/Function"

readonly error: E
readonly annotation: StackAnnotation
}

@@ -72,2 +74,3 @@

readonly defect: unknown
readonly annotation: StackAnnotation
}

@@ -79,2 +82,3 @@

readonly fiberId: FiberId.FiberId
readonly annotation: StackAnnotation
}

@@ -124,6 +128,7 @@

/** @internal */
export const fail = <E>(error: E): Exit<E, never> => ({
export const fail = <E>(error: E, annotation: StackAnnotation): Exit<E, never> => ({
[ExitTypeId]: variance,
op: OP_FAIL,
error,
annotation,
[Equal.symbolHash](): number {

@@ -142,6 +147,7 @@ return pipe(

/** @internal */
export const die = (defect: unknown): Exit<never, never> => ({
export const die = (defect: unknown, annotation: StackAnnotation): Exit<never, never> => ({
[ExitTypeId]: variance,
op: OP_DIE,
defect,
annotation,
[Equal.symbolHash](): number {

@@ -160,6 +166,7 @@ return pipe(

/** @internal */
export const interrupt = (fiberId: FiberId.FiberId): Exit<never, never> => ({
export const interrupt = (fiberId: FiberId.FiberId, annotation: StackAnnotation): Exit<never, never> => ({
[ExitTypeId]: variance,
op: OP_INTERRUPT,
fiberId,
annotation,
[Equal.symbolHash](): number {

@@ -166,0 +173,0 @@ return pipe(

@@ -33,19 +33,2 @@ import * as Entry from "@effect/io/internal/stm/entry"

/** @internal */
export const prepareResetJournal = (journal: Journal): () => unknown => {
const saved: Journal = new Map()
for (const entry of journal) {
saved.set(
entry[0],
Entry.copy(entry[1])
)
}
return () => {
journal.clear()
for (const entry of saved) {
journal.set(entry[0], entry[1])
}
}
}
/** @internal */
export const commitJournal = (journal: Journal) => {

@@ -90,5 +73,5 @@ for (const entry of journal) {

export const execTodos = (todos: Map<TxnId.TxnId, Todo>) => {
const todoKeys = Array.from(todos.keys()).sort()
for (const todo of todoKeys) {
todos.get(todo)![1]()
const todosSorted = Array.from(todos.entries()).sort((x, y) => x[0] - y[0])
for (const [_, todo] of todosSorted) {
todo()
}

@@ -114,24 +97,2 @@ }

/** @internal */
export const untrackedTodoTargets = (
oldJournal: Journal,
newJournal: Journal
): Journal => {
const untracked: Journal = new Map()
for (const [ref, entry] of newJournal) {
if (
// We already tracked this one
!oldJournal.has(ref) &&
// This `TRef` was created in the current transaction, so no need to
// add any todos to it, because it cannot be modified from the outside
// until the transaction succeeds; so any todo added to it would never
// succeed.
!entry.isNew
) {
untracked.set(ref, entry)
}
}
return untracked
}
/** @internal */
export const isValid = (journal: Journal): boolean => {

@@ -138,0 +99,0 @@ let valid = true

@@ -0,1 +1,2 @@

import { getCallTrace } from "@effect/io/Debug"
import * as internal from "@effect/io/internal/stm"

@@ -48,7 +49,7 @@ import type * as STM from "@effect/io/internal/stm"

modify<B>(f: (a: A) => readonly [B, A]): STM.STM<never, never, B> {
return internal.effect((journal) => {
const entry = getOrMakeEntry(this, journal)
return internal.withSTMRuntime((_) => {
const entry = getOrMakeEntry(this, _.journal)
const [retValue, newValue] = f(Entry.unsafeGet(entry) as A)
Entry.unsafeSet(entry, newValue)
return retValue
return internal.succeed(retValue)
})

@@ -58,21 +59,55 @@ }

export const make = <A>(evaluate: () => A): STM.STM<never, never, Ref<A>> => {
return internal.effect((journal) => {
const value = evaluate()
/**
* @macro traced
*/
export const make = <A>(value: A): STM.STM<never, never, Ref<A>> => {
const trace = getCallTrace()
return internal.withSTMRuntime((_) => {
const ref = new RefImpl(value)
journal.set(ref, Entry.make(ref, true))
return ref
})
_.journal.set(ref, Entry.make(ref, true))
return internal.succeed(ref)
}).traced(trace)
}
export const get = <A>(self: Ref<A>) => self.modify((a) => [a, a])
/**
* @macro traced
*/
export const get = <A>(self: Ref<A>) => {
const trace = getCallTrace()
return self.modify((a) => [a, a]).traced(trace)
}
export const set = <A>(value: A) => (self: Ref<A>) => self.modify((): [void, A] => [void 0, value])
/**
* @macro traced
*/
export const set = <A>(value: A) =>
(self: Ref<A>) => {
const trace = getCallTrace()
return self.modify((): [void, A] => [void 0, value]).traced(trace)
}
export const getAndSet = <A>(value: A) => (self: Ref<A>) => self.modify((a): [A, A] => [a, value])
/**
* @macro traced
*/
export const getAndSet = <A>(value: A) =>
(self: Ref<A>) => {
const trace = getCallTrace()
return self.modify((a): [A, A] => [a, value]).traced(trace)
}
export const getAndUpdate = <A>(f: (a: A) => A) => (self: Ref<A>) => self.modify((a): [A, A] => [a, f(a)])
/**
* @macro traced
*/
export const getAndUpdate = <A>(f: (a: A) => A) =>
(self: Ref<A>) => {
const trace = getCallTrace()
return self.modify((a): [A, A] => [a, f(a)]).traced(trace)
}
export const getAndUpdateSome = <A>(f: (a: A) => Option.Option<A>) =>
(self: Ref<A>) =>
/**
* @macro traced
*/
export const getAndUpdateSome = <A>(f: (a: A) => Option.Option<A>) => {
const trace = getCallTrace()
return (self: Ref<A>) =>
self.modify((a): [A, A] =>

@@ -83,10 +118,28 @@ pipe(

)
)
).traced(trace)
}
export const setAndGet = <A>(value: A) => (self: Ref<A>) => self.modify((): [A, A] => [value, value])
/**
* @macro traced
*/
export const setAndGet = <A>(value: A) =>
(self: Ref<A>) => {
const trace = getCallTrace()
return self.modify((): [A, A] => [value, value]).traced(trace)
}
export const modify = <A, B>(f: (a: A) => readonly [B, A]) => (self: Ref<A>) => self.modify(f)
/**
* @macro traced
*/
export const modify = <A, B>(f: (a: A) => readonly [B, A]) => {
const trace = getCallTrace()
return (self: Ref<A>) => self.modify(f).traced(trace)
}
export const modifySome = <A, B>(fallback: B, f: (a: A) => Option.Option<readonly [B, A]>) =>
(self: Ref<A>) =>
/**
* @macro traced
*/
export const modifySome = <A, B>(fallback: B, f: (a: A) => Option.Option<readonly [B, A]>) => {
const trace = getCallTrace()
return (self: Ref<A>) =>
self.modify((a) =>

@@ -100,18 +153,42 @@ pipe(

)
)
).traced(trace)
}
export const update = <A>(f: (a: A) => A) => (self: Ref<A>) => self.modify((a): [void, A] => [void 0, f(a)])
/**
* @macro traced
*/
export const update = <A>(f: (a: A) => A) => {
const trace = getCallTrace()
return (self: Ref<A>) => self.modify((a): [void, A] => [void 0, f(a)]).traced(trace)
}
export const updateAndGet = <A>(f: (a: A) => A) =>
(self: Ref<A>) =>
/**
* @macro traced
*/
export const updateAndGet = <A>(f: (a: A) => A) => {
const trace = getCallTrace()
return (self: Ref<A>) =>
self.modify((a): [A, A] => {
const b = f(a)
return [b, b]
})
}).traced(trace)
}
export const updateSome = <A>(f: (a: A) => Option.Option<A>) =>
(self: Ref<A>) => self.modify((a): [void, A] => [void 0, pipe(f(a), Option.match(() => a, (b) => b))])
/**
* @macro traced
*/
export const updateSome = <A>(f: (a: A) => Option.Option<A>) => {
const trace = getCallTrace()
return (self: Ref<A>) =>
self.modify((a): [void, A] => [void 0, pipe(f(a), Option.match(() => a, (b) => b))]).traced(trace)
}
export const updateSomeAndGet = <A>(f: (a: A) => Option.Option<A>) =>
(self: Ref<A>) => self.modify((a): [A, A] => pipe(f(a), Option.match(() => [a, a], (b) => [b, b])))
/**
* @macro traced
*/
export const updateSomeAndGet = <A>(f: (a: A) => Option.Option<A>) => {
const trace = getCallTrace()
return (self: Ref<A>) =>
self.modify((a): [A, A] => pipe(f(a), Option.match(() => [a, a], (b) => [b, b]))).traced(trace)
}

@@ -118,0 +195,0 @@ const getOrMakeEntry = <A>(self: Ref<A>, journal: Journal.Journal): Entry.Entry => {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc