diff --git a/types/deasync/deasync-tests.ts b/types/deasync/deasync-tests.ts new file mode 100644 index 0000000000..e4e77561e9 --- /dev/null +++ b/types/deasync/deasync-tests.ts @@ -0,0 +1,24 @@ +import * as deasync from "deasync"; + +function asyncFunction(input: number, cb: (res: number) => void) {} +function handle(res: number) {} + +// base case +asyncFunction(42, handle); + +// deasync +let wrapped = deasync(asyncFunction); +handle(wrapped(42)); + +// deasync.loopWhile +let done = false; +asyncFunction(42, () => { + done = true; +}); +deasync.loopWhile(() => !done); + +// deasync.runLoopOnce +deasync.runLoopOnce(); + +// deasync.sleep +deasync.sleep(100); diff --git a/types/deasync/index.d.ts b/types/deasync/index.d.ts new file mode 100644 index 0000000000..20440203e7 --- /dev/null +++ b/types/deasync/index.d.ts @@ -0,0 +1,14 @@ +// Type definitions for deasync 0.1 +// Project: https://github.com/abbr/deasync +// Definitions by: Matt Rollins +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.1 + +export = deasync; + +declare function deasync(fn: (...args: any[]) => void): (...args: any[]) => any; +declare namespace deasync { + function loopWhile(pred: () => boolean): void; + function runLoopOnce(): void; + function sleep(ms: number): void; +} diff --git a/types/deasync/tsconfig.json b/types/deasync/tsconfig.json new file mode 100644 index 0000000000..5b96318954 --- /dev/null +++ b/types/deasync/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "deasync-tests.ts" + ] +} diff --git a/types/deasync/tslint.json b/types/deasync/tslint.json new file mode 100644 index 0000000000..c6c6df5352 --- /dev/null +++ b/types/deasync/tslint.json @@ -0,0 +1,4 @@ +{ + "extends": "dtslint/dt.json", + "rules": {} +}