diff --git a/types/wait-promise/index.d.ts b/types/wait-promise/index.d.ts new file mode 100644 index 0000000000..b20459d661 --- /dev/null +++ b/types/wait-promise/index.d.ts @@ -0,0 +1,32 @@ +// Type definitions for wait-promise 0.4 +// Project: https://github.com/akira-cn/wait-promise +// Definitions by: Paul Melnikow +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.1 + +export interface Wait { + before(time: number): this; + and(func: () => void): this; + after(time: number): this; + every(interval: number, limit?: number): this; + limit(limit: number): this; + check(cond: () => T): Promise; + check(): Promise; + // The promise returned by `forward()` never resolves. + forward(): Promise; + till(cond: () => T): Promise; + until(cond: () => T): Promise; +} + +export function every(interval: number, limit?: number): Wait; +export function and(func: () => void): Wait; +export function limit(limit: number): Wait; +export function before(time: number): Wait; +export function after(time: number): Wait; +export function sleep(time: number): Promise; +export function until(cond: () => T): Promise; +// The promise returned by `forward()` never resolves. +export function forward(): Promise; +export function till(cond: () => T): Promise; +export function check(cond: () => T): Promise; +export function check(): Promise; diff --git a/types/wait-promise/tsconfig.json b/types/wait-promise/tsconfig.json new file mode 100644 index 0000000000..61ccd932af --- /dev/null +++ b/types/wait-promise/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "wait-promise-tests.ts" + ] +} diff --git a/types/wait-promise/tslint.json b/types/wait-promise/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/wait-promise/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } diff --git a/types/wait-promise/wait-promise-tests.ts b/types/wait-promise/wait-promise-tests.ts new file mode 100644 index 0000000000..4ee7e5f8d5 --- /dev/null +++ b/types/wait-promise/wait-promise-tests.ts @@ -0,0 +1,27 @@ +import * as wait from "wait-promise"; + +function exampleVoidFn() {} + +async function testExamples() { + await wait.check(); + const results = [ + await wait.check(() => true), + await wait.until(() => true), + await wait.till(() => true), + await wait.before(500).until(() => true), + await wait.after(500).until(() => true), + await wait.limit(10).until(() => true), + await wait.every(500).until(() => true), + await wait.every(500, 10).until(() => true), + await wait.and(exampleVoidFn).until(() => true), + await wait + .every(50) + .and(exampleVoidFn) + .until(() => true) + ]; + await wait + .every(500) + .and(exampleVoidFn) + .forward(); + await wait.sleep(200); +}