Merge pull request #18230 from Sicilica/master

typings for deasync
This commit is contained in:
Wesley Wigham
2017-07-19 14:10:27 -07:00
committed by GitHub
4 changed files with 64 additions and 0 deletions

View File

@@ -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);

14
types/deasync/index.d.ts vendored Normal file
View File

@@ -0,0 +1,14 @@
// Type definitions for deasync 0.1
// Project: https://github.com/abbr/deasync
// Definitions by: Matt Rollins <https://github.com/Sicilica>
// 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;
}

View File

@@ -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"
]
}

View File

@@ -0,0 +1,4 @@
{
"extends": "dtslint/dt.json",
"rules": {}
}