##// END OF EJS Templates
Code cleanup,...
Code cleanup, remove explicit export object from modules initial work docs/observable.ru.md

File last commit:

r22:93dca6f27f52 propose observables
r22:93dca6f27f52 propose observables
Show More
TestTraits.ts
61 lines | 1.7 KiB | video/mp2t | TypeScriptLexer
cin
Code cleanup,...
r22 import { IObservable, ICancellation, IDestroyable } from "@implab/core/interfaces";
import { Cancellation } from "@implab/core/Cancellation";
import { TraceEvent, LogLevel, WarnLevel } from "@implab/core/log/TraceSource";
cin
fixed format-compile bug while formatting strings with new line symbols....
r15 import * as tape from 'tape';
cin
Code cleanup,...
r22 import { argumentNotNull } from "@implab/core/safe";
cin
fixed format-compile bug while formatting strings with new line symbols....
r15
export class TapeWriter implements IDestroyable {
readonly _tape: tape.Test
_subscriptions = new Array<IDestroyable>();
constructor(tape: tape.Test) {
argumentNotNull(tape, "tape");
this._tape = tape;
}
writeEvents(source: IObservable<TraceEvent>, ct: ICancellation = Cancellation.none) {
let subscription = source.on(this.writeEvent.bind(this));
if (ct.isSupported()) {
ct.register(subscription.destroy.bind(subscription));
}
this._subscriptions.push(subscription);
}
writeEvent(next: TraceEvent) {
cin
Code cleanup,...
r22 if (next.level >= LogLevel) {
cin
fixed format-compile bug while formatting strings with new line symbols....
r15 this._tape.comment("LOG " + next.arg);
cin
Code cleanup,...
r22 } else if (next.level >= WarnLevel) {
cin
fixed format-compile bug while formatting strings with new line symbols....
r15 this._tape.comment("WARN " + next.arg);
} else {
this._tape.comment("ERROR " + next.arg);
}
}
destroy() {
this._subscriptions.forEach(x => x.destroy());
}
cin
added CancellationTests...
r18 }
export async function delay(timeout: number, ct: ICancellation = Cancellation.none) {
let un: IDestroyable;
try {
await new Promise((resolve, reject) => {
if (ct.isRequested()) {
un = ct.register(reject);
} else {
let ht = setTimeout(() => {
resolve();
}, timeout);
un = ct.register(e => {
clearTimeout(ht);
reject(e);
});
}
});
} finally {
if(un)
un.destroy();
};
cin
fixed format-compile bug while formatting strings with new line symbols....
r15 }