Comparing version 28.1.3 to 29.0.0
@@ -6,2 +6,34 @@ # Change Log | ||
# [29.0.0](https://github.com/tusharmath/qio/compare/v28.1.3...v29.0.0) (2019-12-20) | ||
### Bug Fixes | ||
* **managed:** fix resource holding ([908db4b](https://github.com/tusharmath/qio/commit/908db4b89b595b60737f7e5c739e52e2b29e97c2)) | ||
### Code Refactoring | ||
* **fiber:** remove dependency on \`Either\` type internally. ([db926a8](https://github.com/tusharmath/qio/commit/db926a8934013c2543888ae055c329230902078d)) | ||
* **managed:** update function signature for \`Managed.do\` ([75ba5a6](https://github.com/tusharmath/qio/commit/75ba5a63a8d400b878099167953ac9304c396ab4)) | ||
### Features | ||
* **package:** export \`Exit\` for external use ([6c044d0](https://github.com/tusharmath/qio/commit/6c044d07a7167a58206024aeaec6247de5b0e760)) | ||
* **qio:** add \`QIO.bracket_\` ([93428a4](https://github.com/tusharmath/qio/commit/93428a499db48485d8ec8b9dbc8cbee4f4b97128)) | ||
* **qio:** add \`QIO.bracket\` ([a95dfec](https://github.com/tusharmath/qio/commit/a95dfec806f19a6057e7eacd0be5197192d8aef6)) | ||
* **qio:** update types for \`QIO.if\` ([31d5665](https://github.com/tusharmath/qio/commit/31d5665341ed0f8e27ac2720db6cc42dc09e2eb2)) | ||
### BREAKING CHANGES | ||
* **fiber:** \`Fiber.await\` now returns an \`Exit\` status instead of a nested \`Option<Either>\`. This is done to | ||
improve performane and simplify parsing. | ||
* **managed:** Rename \`Managed.do\` to \`Managed.use_\` | ||
## [28.1.3](https://github.com/tusharmath/qio/compare/v28.1.2...v28.1.3) (2019-12-19) | ||
@@ -8,0 +40,0 @@ |
export { Await } from './lib/main/Await'; | ||
export { defaultRuntime } from './lib/runtimes/DefaultRuntime'; | ||
export { Exit } from './lib/main/Exit'; | ||
export { Fiber } from './lib/internals/Fiber'; | ||
@@ -4,0 +5,0 @@ export { FiberConfig } from './lib/internals/FiberConfig'; |
@@ -7,2 +7,4 @@ "use strict"; | ||
exports.defaultRuntime = DefaultRuntime_1.defaultRuntime; | ||
var Exit_1 = require("./lib/main/Exit"); | ||
exports.Exit = Exit_1.Exit; | ||
var Fiber_1 = require("./lib/internals/Fiber"); | ||
@@ -9,0 +11,0 @@ exports.Fiber = Fiber_1.Fiber; |
@@ -1,11 +0,11 @@ | ||
import { Either, Option } from 'standard-data-structures'; | ||
import { ICancellable } from 'ts-scheduler'; | ||
import { Exit } from '../main/Exit'; | ||
import { QIO } from '../main/QIO'; | ||
import { FiberRuntime } from '../runtimes/FiberRuntime'; | ||
import { CBOption } from './CBOption'; | ||
import { CBExit } from './CBExit'; | ||
export declare abstract class Fiber<A, E> { | ||
get join(): QIO<A, E>; | ||
static unsafeExecuteWith<A, E>(io: QIO<A, E>, runtime: FiberRuntime, cb?: CBOption<A, E>): ICancellable; | ||
static unsafeExecuteWith<A, E>(io: QIO<A, E>, runtime: FiberRuntime, cb?: CBExit<A, E>): ICancellable; | ||
abstract abort: QIO<void>; | ||
abstract await: QIO<Option<Either<E, A>>>; | ||
abstract await: QIO<Exit<A, E>>; | ||
readonly id: number; | ||
@@ -17,4 +17,4 @@ abstract runtime: FiberRuntime; | ||
get abort(): QIO<void>; | ||
get await(): QIO<Option<Either<E, A>>>; | ||
static unsafeExecuteWith<A, E>(io: QIO<A, E>, runtime: FiberRuntime, cb?: CBOption<A, E>): FiberContext<A, E>; | ||
get await(): QIO<Exit<A, E>>; | ||
static unsafeExecuteWith<A, E>(io: QIO<A, E>, runtime: FiberRuntime, cb?: CBExit<A, E>): FiberContext<A, E>; | ||
private static dispatchResult; | ||
@@ -24,3 +24,3 @@ private readonly cancellationList; | ||
private readonly observers; | ||
private result; | ||
private result?; | ||
private readonly stackA; | ||
@@ -32,3 +32,3 @@ private readonly stackEnv; | ||
cancel(): void; | ||
unsafeObserve(cb: CBOption<A, E>): ICancellable; | ||
unsafeObserve(cb: CBExit<A, E>): ICancellable; | ||
private dispatchResult; | ||
@@ -35,0 +35,0 @@ private init; |
@@ -5,2 +5,3 @@ "use strict"; | ||
const standard_data_structures_1 = require("standard-data-structures"); | ||
const Exit_1 = require("../main/Exit"); | ||
const Instructions_1 = require("../main/Instructions"); | ||
@@ -28,3 +29,3 @@ const QIO_1 = require("../main/QIO"); | ||
get join() { | ||
return this.await.chain(O => O.map(QIO_1.QIO.fromEither).getOrElse(QIO_1.QIO.never())); | ||
return this.await.chain(QIO_1.QIO.fromExit); | ||
} | ||
@@ -42,3 +43,2 @@ static unsafeExecuteWith(io, runtime, cb) { | ||
this.observers = standard_data_structures_1.DoublyLinkedList.of(); | ||
this.result = standard_data_structures_1.Option.none(); | ||
this.stackA = new Array(); | ||
@@ -78,3 +78,3 @@ this.stackEnv = new Array(); | ||
this.cancellationList.cancel(); | ||
this.observers.map(_ => _(standard_data_structures_1.Option.none())); | ||
this.observers.map(_ => _(Exit_1.Exit.cancel())); | ||
} | ||
@@ -84,5 +84,5 @@ unsafeObserve(cb) { | ||
if (this.status === FiberStatus.CANCELLED) { | ||
return this.runtime.scheduler.asap(FiberContext.dispatchResult, standard_data_structures_1.Option.none(), cb); | ||
return this.runtime.scheduler.asap(FiberContext.dispatchResult, Exit_1.Exit.cancel(), cb); | ||
} | ||
if (this.status === FiberStatus.COMPLETED) { | ||
if (this.status === FiberStatus.COMPLETED && this.result !== undefined) { | ||
return this.runtime.scheduler.asap(FiberContext.dispatchResult, this.result, cb); | ||
@@ -105,4 +105,4 @@ } | ||
this.status = FiberStatus.COMPLETED; | ||
this.result = standard_data_structures_1.Option.some(result); | ||
this.observers.map(_ => _(this.result)); | ||
this.result = result; | ||
this.observers.map(_ => _(result)); | ||
} | ||
@@ -125,3 +125,3 @@ init(data) { | ||
if (j === undefined) { | ||
return this.dispatchResult(standard_data_structures_1.Either.right(data)); | ||
return this.dispatchResult(Exit_1.Exit.succeed(data)); | ||
} | ||
@@ -149,3 +149,3 @@ switch (j.tag) { | ||
else { | ||
return this.dispatchResult(standard_data_structures_1.Either.left(cause)); | ||
return this.dispatchResult(Exit_1.Exit.fail(cause)); | ||
} | ||
@@ -152,0 +152,0 @@ break; |
@@ -10,6 +10,6 @@ import { QIO } from './QIO'; | ||
chain<A2, E2, R2>(fn: (a: A1) => Managed<A2, E2, R2>): Managed<A2, E1 | E2, R1 & R2>; | ||
do<A2, E2, R2>(io: QIO<A2, E2, R2>): QIO<A2, E1 | E2, R1 & R2>; | ||
map<A2>(fn: (a: A1) => A2): Managed<A2, E1, R1>; | ||
use<A2, E2, R2>(fn: (a: A1) => QIO<A2, E2, R2>): QIO<A2, E1 | E2, R1 & R2>; | ||
use_<A2, E2, R2>(io: QIO<A2, E2, R2>): QIO<A2, E1 | E2, R1 & R2>; | ||
zipWith<A2, E2, R2, X>(that: Managed<A2, E2, R2>, fn: (a1: A1, a2: A2) => X): Managed<X, E1 | E2, R1 & R2>; | ||
} |
@@ -11,3 +11,5 @@ "use strict"; | ||
static make(acquire, release) { | ||
return Managed.of(acquire.chain(a1 => release(a1).map(a2 => Reservation_1.Reservation.of(QIO_1.QIO.resolve(a1).addEnv(), QIO_1.QIO.resolve(a2).addEnv())))); | ||
return Managed.of(acquire | ||
.map(a1 => Reservation_1.Reservation.of(QIO_1.QIO.resolve(a1).addEnv(), release(a1))) | ||
.addEnv()); | ||
} | ||
@@ -29,5 +31,2 @@ static of(reservation) { | ||
} | ||
do(io) { | ||
return this.use(() => io); | ||
} | ||
map(fn) { | ||
@@ -37,11 +36,7 @@ return Managed.of(this.reservation.map(r1 => Reservation_1.Reservation.of(r1.acquire.map(fn), r1.release))); | ||
use(fn) { | ||
return this.reservation.zipWithM(QIO_1.QIO.env(), (R, ENV) => R.acquire | ||
.chain(fn) | ||
.catch(e12 => R.release.and(QIO_1.QIO.reject(e12))) | ||
.chain(a2 => R.release.const(a2)) | ||
.fork() | ||
.chain(F => F.await | ||
.chain(O => O.map(QIO_1.QIO.fromEither).getOrElse(F.join)) | ||
.do(R.release.provide(ENV)))); | ||
return this.reservation.chain(R => R.acquire.bracket_(R.release)(fn)); | ||
} | ||
use_(io) { | ||
return this.use(() => io); | ||
} | ||
zipWith(that, fn) { | ||
@@ -48,0 +43,0 @@ return this.chain(a1 => that.map(a2 => fn(a1, a2))); |
@@ -6,2 +6,3 @@ import { Either } from 'standard-data-structures'; | ||
import { FiberConfig } from '../internals/FiberConfig'; | ||
import { Exit } from '../main/Exit'; | ||
import { IRuntime } from '../runtimes/IRuntime'; | ||
@@ -37,4 +38,5 @@ import { Instruction, Tag } from './Instructions'; | ||
static fromEither<A, E>(exit: Either<E, A>): QIO<A, E>; | ||
static if<E1, R1, A, E2, R2>(cond: boolean, left: QIO<A, E1, R1>, right: QIO<A, E2, R2>): QIO<A, E1 | E2, R1 & R2>; | ||
static if0<T extends unknown[]>(...args: T): <E1, R1, A, E2, R2>(cond: (...args: T) => boolean, left: (...args: T) => QIO<A, E1, R1>, right: (...args: T) => QIO<A, E2, R2>) => QIO<A, E1 | E2, R1 & R2>; | ||
static fromExit<A, E>(exit: Exit<A, E>): QIO<A, E>; | ||
static if<A1, E1, R1, A2, E2, R2>(cond: boolean, left: QIO<A1, E1, R1>, right: QIO<A2, E2, R2>): QIO<A1 | A2, E1 | E2, R1 & R2>; | ||
static if0<T extends unknown[]>(...args: T): <A1, E1, R1, A2, E2, R2>(cond: (...args: T) => boolean, left: (...args: T) => QIO<A1, E1, R1>, right: (...args: T) => QIO<A2, E2, R2>) => QIO<A1 | A2, E1 | E2, R1 & R2>; | ||
static lazy<T extends unknown[], A1, E1, R1>(fn: (...T: T) => QIO<A1, E1, R1>): (...T: T) => QIO<A1, E1, R1>; | ||
@@ -64,2 +66,4 @@ static lift<A1 = unknown, E1 = never>(cb: () => A1): QIO<A1, E1>; | ||
and<A2, E2, R2>(aFb: QIO<A2, E2, R2>): QIO<A2, E1 | E2, R1 & R2>; | ||
bracket<E2, R2>(release: (A1: A1) => QIO<void, E2, R2>): <A3, E3, R3>(usage: (A1: A1) => QIO<A3, E3, R3>) => QIO<A3, E1 | E2 | E3, R1 & R2 & R3>; | ||
bracket_<E2, R2>(release: QIO<void, E2, R2>): <A3, E3, R3>(usage: (A1: A1) => QIO<A3, E3, R3>) => QIO<A3, E1 | E2 | E3, R1 & R2 & R3>; | ||
catch<A2, E2, R2>(aFb: (e: E1) => QIO<A2, E2, R2>): QIO<A1 | A2, E2, R1 & R2>; | ||
@@ -81,3 +85,3 @@ chain<A2, E2, R2>(aFb: (a: A1) => QIO<A2, E2, R2>): QIO<A2, E1 | E2, R1 & R2>; | ||
race<A2, E2, R2>(that: QIO<A2, E2, R2>): QIO<A1 | A2, E1 | E2, R1 & R2>; | ||
raceWith<A2, E2, R2, A3, E3, A4, E4>(that: QIO<A2, E2, R2>, cb1: (exit: Either<E1, A1>, fiber: Fiber<A2, E2>) => QIO<A3, E3>, cb2: (exit: Either<E2, A2>, fiber: Fiber<A1, E1>) => QIO<A4, E4>): QIO<A3 | A4, E3 | E4, R1 & R2>; | ||
raceWith<A2, E2, R2, A3, E3, A4, E4>(that: QIO<A2, E2, R2>, cb1: (exit: Exit<A1, E1>, fiber: Fiber<A2, E2>) => QIO<A3, E3>, cb2: (exit: Exit<A2, E2>, fiber: Fiber<A1, E1>) => QIO<A4, E4>): QIO<A3 | A4, E3 | E4, R1 & R2>; | ||
rejectWith<E2>(error: E2): QIO<A1, E1 | E2, R1>; | ||
@@ -84,0 +88,0 @@ tap<E2, R2>(io: (A1: A1) => QIO<unknown, E2, R2>): QIO<A1, E1 | E2, R1 & R2>; |
@@ -6,2 +6,3 @@ "use strict"; | ||
const standard_data_structures_1 = require("standard-data-structures"); | ||
const Exit_1 = require("../main/Exit"); | ||
const Await_1 = require("./Await"); | ||
@@ -89,2 +90,5 @@ const Instructions_1 = require("./Instructions"); | ||
} | ||
static fromExit(exit) { | ||
return Exit_1.Exit.fold(exit)(QIO.never(), QIO.resolve, QIO.reject); | ||
} | ||
static if(cond, left, right) { | ||
@@ -174,2 +178,10 @@ return (cond ? left : right); | ||
} | ||
bracket(release) { | ||
return usage => this.chain(a1 => usage(a1) | ||
.fork() | ||
.chain(F => F.await.and(release(a1)).chain(_ => F.join))); | ||
} | ||
bracket_(release) { | ||
return this.bracket(() => release); | ||
} | ||
catch(aFb) { | ||
@@ -221,3 +233,3 @@ return QIO.catch(this, aFb); | ||
race(that) { | ||
return this.raceWith(that, (E, F) => F.abort.const(E), (E, F) => F.abort.const(E)).chain(E => QIO.fromEither(E)); | ||
return this.raceWith(that, (E, F) => F.abort.const(E), (E, F) => F.abort.const(E)).chain(E => QIO.fromExit(E)); | ||
} | ||
@@ -231,11 +243,7 @@ raceWith(that, cb1, cb2) { | ||
D('zip', 'L cb'); | ||
return standard_data_structures_1.Option.isSome(exit) | ||
? done.set(cb1(exit.value, R)) | ||
: QIO.resolve(true); | ||
return done.set(cb1(exit, R)).const(true); | ||
}); | ||
const resume2 = R.await.chain(exit => { | ||
D('zip', 'R cb'); | ||
return standard_data_structures_1.Option.isSome(exit) | ||
? done.set(cb2(exit.value, L)) | ||
: QIO.resolve(true); | ||
return done.set(cb2(exit, L)).const(true); | ||
}); | ||
@@ -264,5 +272,5 @@ return resume1 | ||
zipWithPar(that, c) { | ||
return this.raceWith(that, (E, F) => E.biMap(cause => F.abort.and(QIO.reject(cause)), a1 => F.join.map(a2 => c(a1, a2))).reduce(prelude_1.Id, prelude_1.Id), (E, F) => E.biMap(cause => F.abort.and(QIO.reject(cause)), a2 => F.join.map(a1 => c(a1, a2))).reduce(prelude_1.Id, prelude_1.Id)); | ||
return this.raceWith(that, (E, F) => Exit_1.Exit.fold(E)(QIO.never(), value => F.join.map(_ => c(value, _)), cause => F.abort.and(QIO.reject(cause))), (E, F) => Exit_1.Exit.fold(E)(QIO.never(), value => F.join.map(_ => c(_, value)), cause => F.abort.and(QIO.reject(cause)))); | ||
} | ||
} | ||
exports.QIO = QIO; |
@@ -5,2 +5,3 @@ "use strict"; | ||
const FiberConfig_1 = require("../internals/FiberConfig"); | ||
const Exit_1 = require("../main/Exit"); | ||
const FiberRuntime_1 = require("./FiberRuntime"); | ||
@@ -18,3 +19,3 @@ class DefaultRuntime extends FiberRuntime_1.FiberRuntime { | ||
return new Promise((res, rej) => { | ||
this.unsafeExecute(io, O => O.map(_ => _.reduce(rej, res))); | ||
this.unsafeExecute(io, exit => Exit_1.Exit.fold(exit)(undefined, res, rej)); | ||
}); | ||
@@ -21,0 +22,0 @@ } |
import { ICancellable, IScheduler } from 'ts-scheduler'; | ||
import { CBOption } from '../internals/CBOption'; | ||
import { CBExit } from '../internals/CBExit'; | ||
import { FiberConfig } from '../internals/FiberConfig'; | ||
@@ -10,3 +10,3 @@ import { QIO } from '../main/QIO'; | ||
abstract configure(config: FiberConfig): IRuntime; | ||
unsafeExecute<A, E>(io: QIO<A, E>, cb?: CBOption<A, E>): ICancellable; | ||
unsafeExecute<A, E>(io: QIO<A, E>, cb?: CBExit<A, E>): ICancellable; | ||
} |
import { ICancellable, IScheduler } from 'ts-scheduler'; | ||
import { CBOption } from '../internals/CBOption'; | ||
import { CBExit } from '../internals/CBExit'; | ||
import { FiberConfig } from '../internals/FiberConfig'; | ||
@@ -9,3 +9,3 @@ import { QIO } from '../main/QIO'; | ||
configure(config: FiberConfig): IRuntime; | ||
unsafeExecute<A, E>(io: QIO<A, E>, cb?: CBOption<A, E>): ICancellable; | ||
unsafeExecute<A, E>(io: QIO<A, E>, cb?: CBExit<A, E>): ICancellable; | ||
} |
@@ -1,4 +0,4 @@ | ||
import { Either, Option } from 'standard-data-structures'; | ||
import { TestScheduler } from 'ts-scheduler'; | ||
import { FiberConfig } from '../internals/FiberConfig'; | ||
import { Exit } from '../main/Exit'; | ||
import { QIO } from '../main/QIO'; | ||
@@ -12,4 +12,4 @@ import { FiberRuntime } from './FiberRuntime'; | ||
unsafeExecuteSync<A, E>(io: QIO<A, E>): A | E | undefined; | ||
unsafeExecuteSync0<A, E>(io: QIO<A, E>): Option<Either<E, A>>; | ||
unsafeExecuteSync0<A, E>(io: QIO<A, E>): Exit<A, E> | undefined; | ||
} | ||
export declare const testRuntime: (scheduler?: TestScheduler) => TestRuntime; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const prelude_1 = require("@qio/prelude"); | ||
const standard_data_structures_1 = require("standard-data-structures"); | ||
const ts_scheduler_1 = require("ts-scheduler"); | ||
const FiberConfig_1 = require("../internals/FiberConfig"); | ||
const Exit_1 = require("../main/Exit"); | ||
const FiberRuntime_1 = require("./FiberRuntime"); | ||
@@ -18,8 +18,9 @@ class TestRuntime extends FiberRuntime_1.FiberRuntime { | ||
unsafeExecuteSync(io) { | ||
return this.unsafeExecuteSync0(io) | ||
.map(_ => _.reduce(prelude_1.Id, prelude_1.Id)) | ||
.getOrElse(undefined); | ||
const exit = this.unsafeExecuteSync0(io); | ||
return exit !== undefined | ||
? Exit_1.Exit.fold(exit)(undefined, prelude_1.Id, prelude_1.Id) | ||
: undefined; | ||
} | ||
unsafeExecuteSync0(io) { | ||
let result = standard_data_structures_1.Option.none(); | ||
let result; | ||
this.unsafeExecute(io, _ => (result = _)); | ||
@@ -26,0 +27,0 @@ this.scheduler.run(); |
@@ -18,5 +18,5 @@ { | ||
}, | ||
"version": "28.1.3", | ||
"version": "29.0.0", | ||
"dependencies": { | ||
"@qio/prelude": "^28.1.2", | ||
"@qio/prelude": "^29.0.0", | ||
"debug": "^4.1.1", | ||
@@ -40,3 +40,3 @@ "in-node": "^1.0.0", | ||
}, | ||
"gitHead": "030ee4381ad6cecfcbc2070a45c155a05f845fb7" | ||
"gitHead": "c5bf00473e5c462ca856920ed0111bd0b8ac22c6" | ||
} |
67439
54
1487
+ Added@qio/prelude@29.0.5(transitive)
- Removed@qio/prelude@28.1.2(transitive)
Updated@qio/prelude@^29.0.0