Comparing version 18.0.1 to 19.0.0
import { UIO } from '../../src/main/QIO'; | ||
export declare class Snapshot<T = string | number> { | ||
readonly timeline: string[]; | ||
readonly timelineData: [T, number][]; | ||
mark(value: T): UIO<T>; | ||
} |
@@ -6,8 +6,11 @@ "use strict"; | ||
constructor() { | ||
this.timeline = new Array(); | ||
this.timelineData = new Array(); | ||
} | ||
get timeline() { | ||
return this.timelineData.map(_ => _.join('@')); | ||
} | ||
mark(value) { | ||
return QIO_1.QIO.runtime().chain(RTM => QIO_1.UIO(() => void this.timeline.push(value + '@' + RTM.scheduler.now())).const(value)); | ||
return QIO_1.QIO.runtime().chain(RTM => QIO_1.UIO(() => void this.timelineData.push([value, RTM.scheduler.now()])).const(value)); | ||
} | ||
} | ||
exports.Snapshot = Snapshot; |
@@ -7,7 +7,10 @@ /** | ||
export class Snapshot<T = string | number> { | ||
public readonly timeline = new Array<string>() | ||
public get timeline(): string[] { | ||
return this.timelineData.map(_ => _.join('@')) | ||
} | ||
public readonly timelineData = new Array<[T, number]>() | ||
public mark(value: T): UIO<T> { | ||
return QIO.runtime().chain(RTM => | ||
UIO( | ||
() => void this.timeline.push(value + '@' + RTM.scheduler.now()) | ||
() => void this.timelineData.push([value, RTM.scheduler.now()]) | ||
).const(value) | ||
@@ -14,0 +17,0 @@ ) |
@@ -6,2 +6,18 @@ # Change Log | ||
# [19.0.0](https://github.com/tusharmath/qio/compare/v18.0.7...v19.0.0) (2019-10-30) | ||
### Bug Fixes | ||
* **fiber:** handle cancellation callbacks while using await ([a74924d](https://github.com/tusharmath/qio/commit/a74924dff119d4f4041c2946c9d961a87436066a)) | ||
### BREAKING CHANGES | ||
* **fiber:** remove \`Fiber.release\` | ||
## [18.0.1](https://github.com/tusharmath/qio/compare/v18.0.0...v18.0.1) (2019-10-24) | ||
@@ -8,0 +24,0 @@ |
@@ -17,5 +17,5 @@ { | ||
}, | ||
"version": "18.0.1", | ||
"version": "19.0.0", | ||
"dependencies": { | ||
"@qio/prelude": "^18.0.0", | ||
"@qio/prelude": "^19.0.0", | ||
"checked-exceptions": "^1.2.0", | ||
@@ -40,3 +40,3 @@ "debug": "^4.1.1", | ||
}, | ||
"gitHead": "1dbc5afb7f7c23d800a97eb28115429443b1bfa6" | ||
"gitHead": "a08faf1a3ec5382b48a6a61faf91ab6292c82297" | ||
} |
import { Either, Option } from 'standard-data-structures'; | ||
import { ICancellable } from 'ts-scheduler'; | ||
import { IO, QIO, UIO } from '../main/QIO'; | ||
import { IO, UIO } from '../main/QIO'; | ||
import { IRuntime } from '../runtimes/IRuntime'; | ||
@@ -11,5 +11,4 @@ import { CBOption } from './CBOption'; | ||
readonly id: number; | ||
abstract join: QIO<E, A>; | ||
readonly join: IO<E, A>; | ||
abstract runtime: IRuntime; | ||
abstract release(p: UIO<void>): UIO<void>; | ||
} | ||
@@ -20,3 +19,2 @@ export declare class FiberContext<E, A> extends Fiber<E, A> implements ICancellable { | ||
readonly await: UIO<Option<Either<E, A>>>; | ||
readonly join: QIO<E, A>; | ||
static unsafeExecuteWith<E, A>(io: IO<E, A>, runtime: IRuntime, cb?: CBOption<E, A>): FiberContext<E, A>; | ||
@@ -33,3 +31,2 @@ private static dispatchResult; | ||
cancel(): void; | ||
release(p: UIO<void>): UIO<void>; | ||
unsafeObserve(cb: CBOption<E, A>): ICancellable; | ||
@@ -39,3 +36,2 @@ private dispatchResult; | ||
private unsafeEvaluate; | ||
private unsafeRelease; | ||
} |
@@ -25,2 +25,5 @@ "use strict"; | ||
} | ||
get join() { | ||
return this.await.chain(O => O.map(QIO_1.QIO.fromEither).getOrElse(QIO_1.QIO.never())); | ||
} | ||
} | ||
@@ -38,3 +41,3 @@ exports.Fiber = Fiber; | ||
this.status = FiberStatus.PENDING; | ||
D(this.id, 'created'); | ||
D(this.id, 'this.constructor()'); | ||
this.stackA.push(instruction); | ||
@@ -47,11 +50,8 @@ this.init(); | ||
get await() { | ||
D(this.id, 'await'); | ||
D(this.id, 'this.await()'); | ||
return QIO_1.QIO.asyncUIO(cb => { | ||
D(this.id, 'unsafe observe'); | ||
return this.unsafeObserve(cb); | ||
this.unsafeObserve(cb); | ||
return this; | ||
}); | ||
} | ||
get join() { | ||
return QIO_1.QIO.asyncIO((rej, res) => this.unsafeObserve(ob => ob.map(_ => _.reduce(rej, res)))); | ||
} | ||
static unsafeExecuteWith(io, runtime, cb) { | ||
@@ -68,11 +68,11 @@ const context = new FiberContext(io.asInstruction, runtime); | ||
cancel() { | ||
D(this.id, 'this.cancel()'); | ||
D(this.id, 'this.observers.length == ', this.observers.length); | ||
this.status = FiberStatus.CANCELLED; | ||
D(this.id, 'this.status ==', FiberStatus[this.status]); | ||
this.cancellationList.cancel(); | ||
this.observers.map(_ => _(standard_data_structures_1.Option.none())); | ||
} | ||
release(p) { | ||
return QIO_1.UIO(() => this.unsafeRelease(p)); | ||
} | ||
unsafeObserve(cb) { | ||
D(this.id, 'unsafe observe'); | ||
D(this.id, 'this.unsafeObserve()'); | ||
if (this.status === FiberStatus.CANCELLED) { | ||
@@ -85,3 +85,13 @@ return this.runtime.scheduler.asap(FiberContext.dispatchResult, standard_data_structures_1.Option.none(), cb); | ||
const node = this.observers.add(cb); | ||
return { cancel: () => this.observers.remove(node) }; | ||
D(this.id, 'this.status ==', FiberStatus[this.status]); | ||
D(this.id, 'this.observers.add()'); | ||
D(this.id, 'this.observers.length == ', this.observers.length); | ||
return { | ||
cancel: () => { | ||
D(this.id, 'this.observers.length == ', this.observers.length); | ||
this.observers.remove(node); | ||
D(this.id, 'this.observer.remove()'); | ||
D(this.id, 'this.observers.length == ', this.observers.length); | ||
} | ||
}; | ||
} | ||
@@ -196,8 +206,3 @@ dispatchResult(result) { | ||
} | ||
unsafeRelease(p) { | ||
this.cancellationList.push({ | ||
cancel: () => Fiber.unsafeExecuteWith(p, this.runtime) | ||
}); | ||
} | ||
} | ||
exports.FiberContext = FiberContext; |
@@ -58,5 +58,6 @@ /* tslint:disable: no-unbound-method cyclomatic-complexity */ | ||
public readonly id = FIBER_ID++ | ||
public abstract join: QIO<E, A> | ||
public get join(): IO<E, A> { | ||
return this.await.chain(O => O.map(QIO.fromEither).getOrElse(QIO.never())) | ||
} | ||
public abstract runtime: IRuntime | ||
public abstract release(p: UIO<void>): UIO<void> | ||
} | ||
@@ -74,16 +75,15 @@ | ||
} | ||
/** | ||
* Aborting the IO produced by await should abort the complete IO. | ||
*/ | ||
public get await(): UIO<Option<Either<E, A>>> { | ||
D(this.id, 'await') | ||
D(this.id, 'this.await()') | ||
return QIO.asyncUIO(cb => { | ||
D(this.id, 'unsafe observe') | ||
this.unsafeObserve(cb) | ||
return this.unsafeObserve(cb) | ||
return this | ||
}) | ||
} | ||
public get join(): QIO<E, A> { | ||
return QIO.asyncIO<E, A>((rej, res) => | ||
this.unsafeObserve(ob => ob.map(_ => _.reduce(rej, res))) | ||
) | ||
} | ||
@@ -126,3 +126,3 @@ /** | ||
super() | ||
D(this.id, 'created') | ||
D(this.id, 'this.constructor()') | ||
this.stackA.push(instruction) | ||
@@ -133,3 +133,6 @@ this.init() | ||
public cancel(): void { | ||
D(this.id, 'this.cancel()') | ||
D(this.id, 'this.observers.length == ', this.observers.length) | ||
this.status = FiberStatus.CANCELLED | ||
D(this.id, 'this.status ==', FiberStatus[this.status]) | ||
this.cancellationList.cancel() | ||
@@ -140,9 +143,9 @@ | ||
public release(p: UIO<void>): UIO<void> { | ||
return UIO(() => this.unsafeRelease(p)) | ||
} | ||
/** | ||
* The `ICancellable` returned when called will only remove the passed on callback. | ||
* It will never cancel the complete Fiber. | ||
* To cancel the Fiber one must call the [[FiberContext.cancel]] method. | ||
*/ | ||
public unsafeObserve(cb: CBOption<E, A>): ICancellable { | ||
D(this.id, 'unsafe observe') | ||
D(this.id, 'this.unsafeObserve()') | ||
if (this.status === FiberStatus.CANCELLED) { | ||
@@ -164,4 +167,14 @@ return this.runtime.scheduler.asap( | ||
const node = this.observers.add(cb) | ||
D(this.id, 'this.status ==', FiberStatus[this.status]) | ||
D(this.id, 'this.observers.add()') | ||
D(this.id, 'this.observers.length == ', this.observers.length) | ||
return {cancel: () => this.observers.remove(node)} | ||
return { | ||
cancel: () => { | ||
D(this.id, 'this.observers.length == ', this.observers.length) | ||
this.observers.remove(node) | ||
D(this.id, 'this.observer.remove()') | ||
D(this.id, 'this.observers.length == ', this.observers.length) | ||
} | ||
} | ||
} | ||
@@ -315,8 +328,2 @@ | ||
} | ||
private unsafeRelease(p: UIO<void>): void { | ||
this.cancellationList.push({ | ||
cancel: () => Fiber.unsafeExecuteWith(p, this.runtime) | ||
}) | ||
} | ||
} |
@@ -35,3 +35,5 @@ "use strict"; | ||
.chain(a2 => R.release.const(a2)) | ||
.fork.chain(F => F.release(R.release.provide(ENV)).and(F.join))); | ||
.fork.chain(F => F.await.chain(O => O.map(QIO_1.QIO.void) | ||
.getOrElse(R.release.provide(ENV)) | ||
.and(F.join)))); | ||
} | ||
@@ -38,0 +40,0 @@ zipWith(that, fn) { |
@@ -107,3 +107,9 @@ import {List} from 'standard-data-structures' | ||
.chain(a2 => R.release.const(a2)) | ||
.fork.chain(F => F.release(R.release.provide(ENV)).and(F.join)) | ||
.fork.chain(F => | ||
F.await.chain(O => | ||
O.map(QIO.void) | ||
.getOrElse(R.release.provide(ENV)) | ||
.and(F.join) | ||
) | ||
) | ||
) | ||
@@ -110,0 +116,0 @@ } |
232151
6255
Updated@qio/prelude@^19.0.0