Async
Install
$ npm install @dxos/async
Usage
import async from '@dxos/async';
const test = async () => {
const [getValue, setValue] = trigger();
setTimeout(() => {
setValue(100);
}, 1000);
const value = await getValue();
expect(value).toBe(100);
};
API
export function noop(...args: any[]): any[];
export function sleep(timeout: any): Promise<unknown>;
export function timeout(f: any, timeout?: number | undefined): Promise<unknown>;
export function promiseTimeout(promise: Promise<any>, timeout: number): Promise<unknown>;
export function waitForCondition(condFn: Function, timeout?: number | undefined, interval?: number | undefined): any;
export function onEvent(eventEmitter: any, eventName: string, callback: Function): () => any;
export function addListener(eventEmitter: any, eventName: any, callback: any): {
remove: () => any;
};
export function waitForEvent(eventEmitter: any, eventName: string, test?: Function | undefined, timeout?: number | undefined): Promise<unknown>;
export function expectToThrow(test: Function, errType?: ErrorConstructor): Promise<void>;
export class Event<T> {}
export function trigger(timeout?: number): [() => Promise<void>, () => void];
export function trigger<T>(timeout?: number): [() => Promise<T>, (arg: T) => void];
export const useValue: typeof trigger;
export declare class Trigger {}
export declare const latch: (n?: number) => readonly [Promise<number>, () => void];
export declare const sink: (emitter: EventEmitter, event: string, count?: number) => Promise<void>;
Contributing
PRs accepted.
License
GPL-3.0 © DxOS