Remove utils from library

This commit is contained in:
Sami Turcotte 2018-12-02 21:59:49 -05:00
parent f630379c24
commit 95b4235daa
4 changed files with 1 additions and 81 deletions

View File

@ -1067,7 +1067,7 @@ test.cb(
},
);
test("last() yields the last chunk streamed by the given readable stream", async t => {
test("last() resolves to the last chunk streamed by the given readable stream", async t => {
const source = new Readable({ objectMode: true });
const lastPromise = last(source);
source.push("ab");

View File

@ -1,7 +1,5 @@
import { Transform, Readable, Writable, Duplex } from "stream";
import * as _utils from "./utils";
import { ChildProcess } from "child_process";
export const utils = _utils;
export interface ThroughOptions {
objectMode?: boolean;

View File

@ -1,39 +0,0 @@
import test from "ava";
import { expect } from "chai";
import { EventEmitter } from "events";
import { once, sleep, delay } from "./utils";
const TimingErrorMarginMs = 50;
test("sleep() resolves after the specified delay in milliseconds", async t => {
const before = Date.now();
await sleep(200);
const after = Date.now();
expect(after - before).gte(200);
expect(after - before).closeTo(200, TimingErrorMarginMs);
});
test("delay() resolves a value after the specified delay in milliseconds", async t => {
const before = Date.now();
const value = await delay("abc", 200);
const after = Date.now();
expect(value).equal("abc");
expect(after - before).gte(200);
expect(after - before).closeTo(200, TimingErrorMarginMs);
});
test("once() resolves only after the specified event is emitted", async t => {
const emitter = new EventEmitter();
const before = Date.now();
emitter.emit("noise", "is ignored");
setTimeout(() => emitter.emit("done", "some-result"), 200);
const result = await once(emitter, "done");
const after = Date.now();
expect(result).equal("some-result");
expect(after - before).gte(200);
expect(after - before).closeTo(200, TimingErrorMarginMs);
});

View File

@ -1,39 +0,0 @@
/**
* Resolve after the given delay in milliseconds
*
* @param ms The number of milliseconds to wait
*/
export function sleep(ms: number) {
return new Promise(resolve => {
setTimeout(resolve, ms);
});
}
/**
* Resolve a value after the given delay in milliseconds
*
* @param value Value to resolve
* @param ms Number of milliseconds to wait
*/
export function delay<T>(value: T, ms: number): Promise<T> {
return new Promise(resolve => {
setTimeout(() => resolve(value), ms);
});
}
/**
* Resolve once the given event emitter emits the specified event
*
* @param emitter Event emitter to watch
* @param event Event to watch
*/
export function once<T>(
emitter: NodeJS.EventEmitter,
event: string,
): Promise<T> {
return new Promise(resolve => {
emitter.once(event, result => {
resolve(result);
});
});
}