mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
* [d3-collection] Linted * Added and completed linting * Replaced `Object` with `any` adding TODO to change to proper `object` type when publishing the definitions to use TS 2.2+ * [d3-color] Linted * [d3-dispatch] Linted * [d3-hsv] Linted * [d3-interpolate] Linted. `Object` to `any` * Replace use of `Object` as extension basis with `any` for now. Added TODO to change it to use the `object` type, when updating the definitions to formally use TS2.2+ * [d3-path] Linted. * [d3-polygon] Linted. * [d3-quadtree] Linted. * [d3-queue] Linted. * [d3-request] Linted. * [d3-scale-chromatic] Linted. * [d3-time-format] Linted. * [d3-time] Linted. * [d3-timer] Linted. * [d3-voronoi] Linted. * [d3-scale] Move callable-type lint deactivation to tslint.json * line level deactivation was ignored.
94 lines
2.8 KiB
TypeScript
94 lines
2.8 KiB
TypeScript
/**
|
|
* Typescript definition tests for d3/d3-queue module
|
|
*
|
|
* Note: These tests are intended to test the definitions only
|
|
* in the sense of typing and call signature consistency. They
|
|
* are not intended as functional tests.
|
|
*/
|
|
|
|
import * as d3Queue from 'd3-queue';
|
|
|
|
// -------------------------------------------------------------------
|
|
// Test Queue
|
|
// -------------------------------------------------------------------
|
|
|
|
// Create queue ======================================================
|
|
|
|
let qNoResult: d3Queue.Queue;
|
|
let qWithResults: d3Queue.Queue;
|
|
|
|
// With default concurrency
|
|
qNoResult = d3Queue.queue();
|
|
|
|
// With limited concurrency
|
|
qWithResults = d3Queue.queue(3);
|
|
|
|
// Defer Tasks =======================================================
|
|
|
|
// No Results Task ---------------------------------------------------
|
|
|
|
function delayedHello(name: string, delay: number, callback: (error: any | null) => void) {
|
|
setTimeout(() => {
|
|
console.log('Hello, ' + name + '!');
|
|
callback(null);
|
|
}, delay);
|
|
}
|
|
|
|
qNoResult = qNoResult.defer(delayedHello, 'Alice', 250);
|
|
|
|
qNoResult.defer(delayedHello, 'Bob', 500);
|
|
|
|
// Task with Reuslts -------------------------------------------------
|
|
|
|
function getFileStats(path: string, callback: (error: any | null, stats?: any) => void) {
|
|
// magically get file stats and behave like fs.stat when invoking the callback
|
|
}
|
|
|
|
qWithResults
|
|
.defer(getFileStats, './workingpath/file1.json')
|
|
.defer(getFileStats, './yetanotherworkingpath/file2.json');
|
|
|
|
// Await Tasks Completion =============================================
|
|
|
|
// No Results Task ---------------------------------------------------
|
|
|
|
qNoResult = qNoResult.await((error) => {
|
|
if (error) throw error;
|
|
console.log('Goodbye!');
|
|
});
|
|
|
|
// Task with Reuslts -------------------------------------------------
|
|
|
|
// await
|
|
qWithResults
|
|
.await((error, file1Stat, file2Stat) => {
|
|
if (error) throw error;
|
|
console.log(file1Stat, file2Stat);
|
|
});
|
|
|
|
// awaitAll
|
|
|
|
qWithResults = d3Queue.queue()
|
|
.defer(getFileStats, './workingpath/file1.json')
|
|
.defer(getFileStats, './yetanotherworkingpath/file2.json')
|
|
.awaitAll((error, fileStats) => {
|
|
if (error) throw error;
|
|
console.log(fileStats[0], fileStats[1]);
|
|
});
|
|
|
|
// Abort Deferred Tasks ==============================================
|
|
|
|
function requestDataFromInterWeb(url: string, callback: (error: any | null, data?: any) => void) {
|
|
// magically get data from the interweb, e.g. like d3-request would, while supporting an abort() method
|
|
}
|
|
|
|
qWithResults = d3Queue.queue()
|
|
.defer(requestDataFromInterWeb, 'http://www.google.com:81')
|
|
.defer(requestDataFromInterWeb, 'http://www.google.com:81')
|
|
.awaitAll((error, results) => {
|
|
if (error) throw error;
|
|
console.log(results[0], results[1]);
|
|
});
|
|
|
|
qWithResults.abort();
|