feat(nanotimer): complete definition (#42153)

* feat(nanotimer): complete definition

* lint
This commit is contained in:
Samuel Bodin
2020-02-06 15:29:16 -08:00
committed by GitHub
parent a1039ae6e5
commit f44f31789c
4 changed files with 95 additions and 0 deletions
+65
View File
@@ -0,0 +1,65 @@
// Type definitions for nanotimer 0.3
// Project: https://github.com/Krb686/nanotimer
// Definitions by: Samuel Bodin <https://github.com/bodinsamuel>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare namespace NanoTimer {
interface TimeoutResults {
waitTime: number;
}
}
declare class NanoTimer {
/**
* Creates an instance of NanoTimer.
* @param log - if true, will enable logging.
*/
constructor(log?: boolean);
/**
* Call the task after the waiting the the timeout specified.
*/
setTimeout(
task: (...args: any[]) => void,
args: any[] | string,
timeout: string,
callback?: (results: NanoTimer.TimeoutResults) => void,
): void;
/**
* Clears current running timeOut.
*/
clearTimeout(): void;
/**
* Call the task at the regular interval specified in interval.
*/
setInterval(
task: (...args: any[]) => void,
args: any[] | string,
interval: string,
callback?: (error: Error) => void,
): void;
/**
* Clears current running interval.
*/
clearInterval(): void;
/**
* Calculate the time it tooks to execute the task.
*/
time(
task: (cb: () => void) => void,
args: string | any[],
interval: string,
callback?: (error: Error) => void,
): number;
/**
* Returns true if the timer currently has a scheduled timeout, or false otherwise
*/
hasTimeout(): boolean;
}
export = NanoTimer;
+10
View File
@@ -0,0 +1,10 @@
import NanoTimer = require('nanotimer');
const timer = new NanoTimer();
timer.setInterval(() => {}, '', '1s');
timer.setTimeout(() => {}, [timer], '10s');
const runtimeSeconds = timer.time(() => {}, '', 'u');
timer.clearInterval();
timer.clearTimeout();
timer.hasTimeout();
+19
View File
@@ -0,0 +1,19 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": ["es6"],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": ["../"],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"nanotimer-tests.ts"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }