mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-07 00:07:07 +00:00
Add types/tests for wait-promise (#36384)
This commit is contained in:
committed by
Ben Lichtman
parent
5b2f2030a2
commit
e99c4f4e51
Vendored
+32
@@ -0,0 +1,32 @@
|
||||
// Type definitions for wait-promise 0.4
|
||||
// Project: https://github.com/akira-cn/wait-promise
|
||||
// Definitions by: Paul Melnikow <https://github.com/paulmelnikow>
|
||||
// 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<T>(cond: () => T): Promise<T>;
|
||||
check(): Promise<void>;
|
||||
// The promise returned by `forward()` never resolves.
|
||||
forward(): Promise<void>;
|
||||
till<T>(cond: () => T): Promise<T>;
|
||||
until<T>(cond: () => T): Promise<T>;
|
||||
}
|
||||
|
||||
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<void>;
|
||||
export function until<T>(cond: () => T): Promise<T>;
|
||||
// The promise returned by `forward()` never resolves.
|
||||
export function forward(): Promise<void>;
|
||||
export function till<T>(cond: () => T): Promise<T>;
|
||||
export function check<T>(cond: () => T): Promise<T>;
|
||||
export function check(): Promise<void>;
|
||||
@@ -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"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
@@ -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);
|
||||
}
|
||||
Reference in New Issue
Block a user