mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
feat(nanoscheduler): new type definition (#45878)
- definition file - tests https://www.npmjs.com/package/nanoscheduler https://github.com/choojs/nanoscheduler#readme Thanks!
This commit is contained in:
parent
7a7ad43ca1
commit
a5433cbce9
27
types/nanoscheduler/index.d.ts
vendored
Normal file
27
types/nanoscheduler/index.d.ts
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
// Type definitions for nanoscheduler 1.0
|
||||
// Project: https://github.com/choojs/nanoscheduler#readme
|
||||
// Definitions by: Piotr Błażejewicz <https://github.com/peterblazejewicz>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/**
|
||||
* Create a new scheduler instance.
|
||||
* The instance is shared as a singleton on window (if available).
|
||||
*/
|
||||
declare function createScheduler(): scheduler.NanoScheduler;
|
||||
|
||||
declare namespace scheduler {
|
||||
/**
|
||||
* Schedule work to be completed when the user agent is idle. Weighs 270 bytes compressed.
|
||||
*/
|
||||
abstract class NanoScheduler {
|
||||
constructor(hasWindow: boolean);
|
||||
/**
|
||||
* Push a callback into the scheduler, to be executed when the user agent is idle.
|
||||
*/
|
||||
push(cb: () => void): void;
|
||||
schedule(): void;
|
||||
setTimeout(cb: () => void): void;
|
||||
}
|
||||
}
|
||||
|
||||
export = createScheduler;
|
||||
15
types/nanoscheduler/nanoscheduler-tests.ts
Normal file
15
types/nanoscheduler/nanoscheduler-tests.ts
Normal file
@ -0,0 +1,15 @@
|
||||
/// <reference lib="DOM" />
|
||||
import NanoScheduler = require('nanoscheduler');
|
||||
|
||||
const scheduler = NanoScheduler(); // $ExpectTYpe NanoScheduler
|
||||
scheduler.push(() => {
|
||||
// callback
|
||||
});
|
||||
scheduler.schedule();
|
||||
scheduler.setTimeout(() => {
|
||||
// done
|
||||
});
|
||||
|
||||
// usage sample
|
||||
let i = 10000;
|
||||
while (i--) scheduler.push(() => console.log(`idle time! ${Date.now()}`));
|
||||
23
types/nanoscheduler/tsconfig.json
Normal file
23
types/nanoscheduler/tsconfig.json
Normal file
@ -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",
|
||||
"nanoscheduler-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/nanoscheduler/tslint.json
Normal file
1
types/nanoscheduler/tslint.json
Normal file
@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Loading…
Reference in New Issue
Block a user