@matechs/effect
Advanced tools
Comparing version 6.0.0-beta.1 to 6.0.0-beta.2
@@ -73,4 +73,7 @@ import { either as E, function as F } from "fp-ts"; | ||
handle(e: Cause<unknown>): T.Instructions | undefined; | ||
dispatchResumeInterrupt(err?: Error): void; | ||
resumeInterrupt(err?: Error): void; | ||
dispatchResumeInterrupt(_: { | ||
err?: Error; | ||
others?: Error[]; | ||
}): void; | ||
resumeInterrupt(err?: Error, others?: Error[]): void; | ||
next(value: unknown): T.Instructions | undefined; | ||
@@ -77,0 +80,0 @@ foldResume(status: E.Either<unknown, unknown>): void; |
@@ -5,3 +5,3 @@ /* | ||
import { either as E, option as O } from "fp-ts"; | ||
import { done, interruptWithError, raise } from "./original/exit"; | ||
import { done, interruptWithError, raise, interruptWithErrorAndOthers } from "./original/exit"; | ||
import { defaultRuntime } from "./original/runtime"; | ||
@@ -115,4 +115,6 @@ import * as T from "./effect"; | ||
} | ||
dispatchResumeInterrupt(err) { | ||
const go = this.handle(interruptWithError(err)); | ||
dispatchResumeInterrupt(_) { | ||
const go = _.others && _.err | ||
? this.handle(interruptWithErrorAndOthers(_.err, _.others)) | ||
: this.handle(interruptWithError(_.err)); | ||
if (go) { | ||
@@ -123,4 +125,4 @@ // eslint-disable-next-line | ||
} | ||
resumeInterrupt(err) { | ||
this.runtime.dispatch(this.dispatchResumeInterrupt.bind(this), err); | ||
resumeInterrupt(err, others) { | ||
this.runtime.dispatch(this.dispatchResumeInterrupt.bind(this), { err, others }); | ||
} | ||
@@ -300,4 +302,4 @@ next(value) { | ||
if (this.cancelAsync && this.isInterruptible()) { | ||
this.cancelAsync((err) => { | ||
this.resumeInterrupt(err); | ||
this.cancelAsync((err, others) => { | ||
this.resumeInterrupt(err, others); | ||
}); | ||
@@ -304,0 +306,0 @@ } |
@@ -53,3 +53,3 @@ import { either as Ei, function as F, option as Op, task as TA, taskEither as TE, semigroup as Sem, monoid as Mon, tree as TR } from "fp-ts"; | ||
export declare type AsyncContFn<E, A> = F.FunctionN<[Ei.Either<E, A>], void>; | ||
export declare type AsyncCancelContFn = F.FunctionN<[(error?: Error) => void], void>; | ||
export declare type AsyncCancelContFn = F.FunctionN<[(error?: Error, others?: Error[]) => void], void>; | ||
export declare type AsyncFn<E, A> = F.FunctionN<[AsyncContFn<E, A>], AsyncCancelContFn>; | ||
@@ -56,0 +56,0 @@ export interface IAsync<E = unknown, A = unknown> { |
@@ -508,3 +508,7 @@ import { either as Ei, function as F, option as Op, array as Ar, tree as TR, record as RE } from "fp-ts"; | ||
if (finalize._tag === "Done") { | ||
const errors = pipe([exit.error, ...finalize.value.map((x) => x.error)], Ar.filter((x) => x !== undefined)); | ||
const errors = pipe([ | ||
exit.error, | ||
...(exit.others ? exit.others : []), | ||
...Ar.flatten(finalize.value.map((x) => [x.error, ...(x.others ? x.others : [])])) | ||
], Ar.filter((x) => x !== undefined)); | ||
return errors.length > 0 | ||
@@ -511,0 +515,0 @@ ? completed(ex.interruptWithErrorAndOthers(errors[0], Ar.dropLeft(1)(errors))) |
@@ -12,3 +12,3 @@ import { function as F } from "fp-ts"; | ||
*/ | ||
set(a: A): T.Sync<A>; | ||
readonly set: (a: A) => T.Sync<A>; | ||
/** | ||
@@ -19,3 +19,3 @@ * Update the current value of the ref with a function. | ||
*/ | ||
update(f: F.FunctionN<[A], A>): T.Sync<A>; | ||
readonly update: (f: F.FunctionN<[A], A>) => T.Sync<A>; | ||
/** | ||
@@ -27,8 +27,8 @@ * Update the current value of a ref with a function. | ||
*/ | ||
modify<B>(f: F.FunctionN<[A], readonly [B, A]>): T.Sync<B>; | ||
readonly modify: <B>(f: F.FunctionN<[A], readonly [B, A]>) => T.Sync<B>; | ||
} | ||
/** | ||
* Creates an IO that will allocate a Ref. | ||
* Curried form of makeRef_ to allow for inference on the initial type | ||
* Curried form of makeRef to allow for inference on the initial type | ||
*/ | ||
export declare const makeRef: <A>(initial: A) => T.Sync<Ref<A>>; |
@@ -5,26 +5,32 @@ /* | ||
import * as T from "./effect"; | ||
class RefImpl { | ||
constructor(initial) { | ||
this.get = T.sync(() => this.value); | ||
this.value = initial; | ||
this.set = this.set.bind(this); | ||
this.modify = this.modify.bind(this); | ||
this.update = this.update.bind(this); | ||
} | ||
set(a) { | ||
return T.sync(() => { | ||
const prev = this.value; | ||
this.value = a; | ||
return prev; | ||
}); | ||
} | ||
modify(f) { | ||
return T.sync(() => { | ||
const [b, a] = f(this.value); | ||
this.value = a; | ||
return b; | ||
}); | ||
} | ||
update(f) { | ||
return T.sync(() => (this.value = f(this.value))); | ||
} | ||
} | ||
/** | ||
* Creates an IO that will allocate a Ref. | ||
* Curried form of makeRef_ to allow for inference on the initial type | ||
* Curried form of makeRef to allow for inference on the initial type | ||
*/ | ||
export const makeRef = (initial) => T.sync(() => { | ||
let value = initial; | ||
const get = T.sync(() => value); | ||
const set = (a) => T.sync(() => { | ||
const prev = value; | ||
value = a; | ||
return prev; | ||
}); | ||
const update = (f) => T.sync(() => (value = f(value))); | ||
const modify = (f) => T.sync(() => { | ||
const [b, a] = f(value); | ||
value = a; | ||
return b; | ||
}); | ||
return { | ||
get, | ||
set, | ||
update, | ||
modify | ||
}; | ||
}); | ||
export const makeRef = (initial) => T.sync(() => new RefImpl(initial)); |
@@ -73,4 +73,7 @@ import { either as E, function as F } from "fp-ts"; | ||
handle(e: Cause<unknown>): T.Instructions | undefined; | ||
dispatchResumeInterrupt(err?: Error): void; | ||
resumeInterrupt(err?: Error): void; | ||
dispatchResumeInterrupt(_: { | ||
err?: Error; | ||
others?: Error[]; | ||
}): void; | ||
resumeInterrupt(err?: Error, others?: Error[]): void; | ||
next(value: unknown): T.Instructions | undefined; | ||
@@ -77,0 +80,0 @@ foldResume(status: E.Either<unknown, unknown>): void; |
@@ -129,4 +129,6 @@ "use strict"; | ||
}; | ||
DriverImpl.prototype.dispatchResumeInterrupt = function (err) { | ||
var go = this.handle(exit_1.interruptWithError(err)); | ||
DriverImpl.prototype.dispatchResumeInterrupt = function (_) { | ||
var go = _.others && _.err | ||
? this.handle(exit_1.interruptWithErrorAndOthers(_.err, _.others)) | ||
: this.handle(exit_1.interruptWithError(_.err)); | ||
if (go) { | ||
@@ -137,4 +139,4 @@ // eslint-disable-next-line | ||
}; | ||
DriverImpl.prototype.resumeInterrupt = function (err) { | ||
this.runtime.dispatch(this.dispatchResumeInterrupt.bind(this), err); | ||
DriverImpl.prototype.resumeInterrupt = function (err, others) { | ||
this.runtime.dispatch(this.dispatchResumeInterrupt.bind(this), { err: err, others: others }); | ||
}; | ||
@@ -322,4 +324,4 @@ DriverImpl.prototype.next = function (value) { | ||
if (this.cancelAsync && this.isInterruptible()) { | ||
this.cancelAsync(function (err) { | ||
_this.resumeInterrupt(err); | ||
this.cancelAsync(function (err, others) { | ||
_this.resumeInterrupt(err, others); | ||
}); | ||
@@ -326,0 +328,0 @@ } |
@@ -53,3 +53,3 @@ import { either as Ei, function as F, option as Op, task as TA, taskEither as TE, semigroup as Sem, monoid as Mon, tree as TR } from "fp-ts"; | ||
export declare type AsyncContFn<E, A> = F.FunctionN<[Ei.Either<E, A>], void>; | ||
export declare type AsyncCancelContFn = F.FunctionN<[(error?: Error) => void], void>; | ||
export declare type AsyncCancelContFn = F.FunctionN<[(error?: Error, others?: Error[]) => void], void>; | ||
export declare type AsyncFn<E, A> = F.FunctionN<[AsyncContFn<E, A>], AsyncCancelContFn>; | ||
@@ -56,0 +56,0 @@ export interface IAsync<E = unknown, A = unknown> { |
@@ -621,3 +621,5 @@ "use strict"; | ||
if (finalize._tag === "Done") { | ||
var errors = pipeable_1.pipe(__spreadArrays([exit.error], finalize.value.map(function (x) { return x.error; })), fp_ts_1.array.filter(function (x) { return x !== undefined; })); | ||
var errors = pipeable_1.pipe(__spreadArrays([ | ||
exit.error | ||
], (exit.others ? exit.others : []), fp_ts_1.array.flatten(finalize.value.map(function (x) { return __spreadArrays([x.error], (x.others ? x.others : [])); }))), fp_ts_1.array.filter(function (x) { return x !== undefined; })); | ||
return errors.length > 0 | ||
@@ -624,0 +626,0 @@ ? completed(ex.interruptWithErrorAndOthers(errors[0], fp_ts_1.array.dropLeft(1)(errors))) |
@@ -12,3 +12,3 @@ import { function as F } from "fp-ts"; | ||
*/ | ||
set(a: A): T.Sync<A>; | ||
readonly set: (a: A) => T.Sync<A>; | ||
/** | ||
@@ -19,3 +19,3 @@ * Update the current value of the ref with a function. | ||
*/ | ||
update(f: F.FunctionN<[A], A>): T.Sync<A>; | ||
readonly update: (f: F.FunctionN<[A], A>) => T.Sync<A>; | ||
/** | ||
@@ -27,8 +27,8 @@ * Update the current value of a ref with a function. | ||
*/ | ||
modify<B>(f: F.FunctionN<[A], readonly [B, A]>): T.Sync<B>; | ||
readonly modify: <B>(f: F.FunctionN<[A], readonly [B, A]>) => T.Sync<B>; | ||
} | ||
/** | ||
* Creates an IO that will allocate a Ref. | ||
* Curried form of makeRef_ to allow for inference on the initial type | ||
* Curried form of makeRef to allow for inference on the initial type | ||
*/ | ||
export declare const makeRef: <A>(initial: A) => T.Sync<Ref<A>>; |
@@ -14,32 +14,37 @@ "use strict"; | ||
var T = __importStar(require("./effect")); | ||
var RefImpl = /** @class */ (function () { | ||
function RefImpl(initial) { | ||
var _this = this; | ||
this.get = T.sync(function () { return _this.value; }); | ||
this.value = initial; | ||
this.set = this.set.bind(this); | ||
this.modify = this.modify.bind(this); | ||
this.update = this.update.bind(this); | ||
} | ||
RefImpl.prototype.set = function (a) { | ||
var _this = this; | ||
return T.sync(function () { | ||
var prev = _this.value; | ||
_this.value = a; | ||
return prev; | ||
}); | ||
}; | ||
RefImpl.prototype.modify = function (f) { | ||
var _this = this; | ||
return T.sync(function () { | ||
var _a = f(_this.value), b = _a[0], a = _a[1]; | ||
_this.value = a; | ||
return b; | ||
}); | ||
}; | ||
RefImpl.prototype.update = function (f) { | ||
var _this = this; | ||
return T.sync(function () { return (_this.value = f(_this.value)); }); | ||
}; | ||
return RefImpl; | ||
}()); | ||
/** | ||
* Creates an IO that will allocate a Ref. | ||
* Curried form of makeRef_ to allow for inference on the initial type | ||
* Curried form of makeRef to allow for inference on the initial type | ||
*/ | ||
exports.makeRef = function (initial) { | ||
return T.sync(function () { | ||
var value = initial; | ||
var get = T.sync(function () { return value; }); | ||
var set = function (a) { | ||
return T.sync(function () { | ||
var prev = value; | ||
value = a; | ||
return prev; | ||
}); | ||
}; | ||
var update = function (f) { return T.sync(function () { return (value = f(value)); }); }; | ||
var modify = function (f) { | ||
return T.sync(function () { | ||
var _a = f(value), b = _a[0], a = _a[1]; | ||
value = a; | ||
return b; | ||
}); | ||
}; | ||
return { | ||
get: get, | ||
set: set, | ||
update: update, | ||
modify: modify | ||
}; | ||
}); | ||
}; | ||
exports.makeRef = function (initial) { return T.sync(function () { return new RefImpl(initial); }); }; |
{ | ||
"name": "@matechs/effect", | ||
"version": "6.0.0-beta.1", | ||
"version": "6.0.0-beta.2", | ||
"license": "MIT", | ||
@@ -42,3 +42,3 @@ "private": false, | ||
}, | ||
"gitHead": "030e6a8c189895a7dfd4efb2d993a2aa182cd189" | ||
"gitHead": "c39805387fffa1370304c9cbbaa3c2fba380a49e" | ||
} |
628094
14897