From f3103378e6ff29b3434b2343680ad3d3978f3826 Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Wed, 20 Dec 2017 13:01:40 -0800 Subject: [PATCH] asyncblock: Provides its own types --- notNeededPackages.json | 6 + types/asyncblock/asyncblock-tests.ts | 189 --------------------------- types/asyncblock/index.d.ts | 71 ---------- types/asyncblock/tsconfig.json | 24 ---- types/asyncblock/tslint.json | 79 ----------- 5 files changed, 6 insertions(+), 363 deletions(-) delete mode 100644 types/asyncblock/asyncblock-tests.ts delete mode 100644 types/asyncblock/index.d.ts delete mode 100644 types/asyncblock/tsconfig.json delete mode 100644 types/asyncblock/tslint.json diff --git a/notNeededPackages.json b/notNeededPackages.json index 2cd00992e5..9ac393c549 100644 --- a/notNeededPackages.json +++ b/notNeededPackages.json @@ -60,6 +60,12 @@ "sourceRepoURL": "https://github.com/AlexTeixeira/Askmethat-Rating", "asOfVersion": "0.4.0" }, + { + "libraryName": "asyncblock", + "typingsPackageName": "asyncblock", + "sourceRepoURL": "https://github.com/scriby/asyncblock", + "asOfVersion": "2.2.11" + }, { "libraryName": "aurelia-knockout", "typingsPackageName": "aurelia-knockout", diff --git a/types/asyncblock/asyncblock-tests.ts b/types/asyncblock/asyncblock-tests.ts deleted file mode 100644 index d93c9fc07a..0000000000 --- a/types/asyncblock/asyncblock-tests.ts +++ /dev/null @@ -1,189 +0,0 @@ - -/// - -import asyncblock = require('asyncblock'); -import fs = require('fs'); - - -// Sleeping in series -asyncblock((flow: asyncblock.IFlow) => { - console.time('time'); - - setTimeout(flow.add(), 1000); - flow.wait(); //Wait for the first setTimeout to finish - - setTimeout(flow.add(), 2000); - flow.wait(); //Wait for the second setTimeout to finish - - console.timeEnd('time'); //3 seconds -}); - -// Trapping results -asyncblock((flow) => { - var path1 = '', path2 = ''; - //Start two parallel file reads - fs.readFile(path1, 'utf8', flow.set('contents1')); - fs.readFile(path2, 'utf8', flow.set('contents2')); - - //Print the concatenation of the results when both reads are finished - console.log(flow.get('contents1') + flow.get('contents2')); - - var paths: string[] = []; - //Wait for a large number of tasks - for(var i = 0; i < 100; i++){ - //Add each task in parallel with i as the key - fs.readFile(paths[i], 'utf8', flow.add(i)); - } - - //Wait for all the tasks to finish. Results is an object of the form {key1: value1, key2: value2, ...} - var results = flow.wait(); - - var path = ''; - //One-liner syntax for waiting on a single task - var contents = flow.sync( fs.readFile(path, 'utf8', flow.callback()) ); - - //See overview & API docs for more extensive description of techniques -}); - -// Error handling -var asyncTask = (callback: (err: any) => void) => { - asyncblock((flow) => { - flow.errorCallback = callback; //Setting the errorCallback is the easiest way to perform error handling. If erroCallback isn't set, and an error occurs, it will be thrown instead of returned to the callback - - var path = ''; - fs.readFile(path, 'utf8', flow.add()); //If readFile encountered an error, it would automatically get passed to the callback - var contents = flow.wait(); - - console.log(contents); //If an error occured above, this code won't run - }); -}; - -// Returning results -var asyncTask2 = (callback: (err: any, res: string) => void) => { - asyncblock((flow) => { - var path = ''; - var contents = flow.sync( fs.readFile(path, 'utf8', flow.callback()) ); //If readFile encountered an error, it would automatically get passed to the callback - - return contents; //Return the value you want to be passed to the callback - }, callback); //The callback can be specified as the 2nd arg to asyncblock. It will be called with the value returned from the asyncblock as the 2nd arg. - //If an error occurs, the callback will be called with the error as the first argument. -}; - - -// Sample -asyncblock.nostack((flow) => { - fs.readFile('path1', 'utf8', flow.add('first')); - fs.readFile('path2', 'utf8', flow.add('second')); - - //Wait until done reading the first and second files, then write them to another file - fs.writeFile('path3', flow.wait('first') + flow.wait('second'), flow.add()); - flow.wait(); //Wait on all outstanding tasks - - fs.readFile('path3', 'utf8', flow.add('data')); - - console.log(flow.wait('data')); //Print the 3rd file's data - console.log('all done'); -}); - - -// Formatting results -(function() { - -var asyncTask = function(callback: (err: any, res1: number, res2: number, res3: number) => void) { - process.nextTick(function() { - callback(null, 1, 2, 3); - }); -} - -asyncblock(function(flow) { - asyncTask(flow.add()); - - var result = flow.wait(); - console.log(result); // Prints 1 -}); - -asyncblock(function(flow) { - asyncTask(flow.add(['first', 'second', 'third'])); - - var result = flow.wait(); - console.log(result); // Prints { first: 1, second: 2, third: 3 } - - asyncTask(flow.add('key1', ['first', 'second', 'third'])); - asyncTask(flow.add('key2', ['a', 'b', 'c'])); - var result = flow.wait(); - console.log(result); // Prints { key1: { first: 1, second: 2, third: 3 }, key2: { a: 1, b: 2, c: 3} } -}); - -})(); - - -// Parallel task rate limiting -(function() { - -asyncblock(function(flow) { - flow.queue(function(callback: Function) { - setTimeout(callback, 1000); - }); - - flow.wait(); //This will wait for about a second -}); - -asyncblock(function(flow) { - flow.maxParallel = 2; - - process.nextTick(function(){ - flow.queue(function(callback: Function) { - setTimeout(callback, 1000); - }); - - flow.queue(function(callback: Function) { - setTimeout(callback, 2000); - }); - - flow.queue(function(callback: Function) { - setTimeout(callback, 3000); - }); - - flow.doneAdding(); - }); - - flow.forceWait(); -}); - -asyncblock(function(flow) { - setTimeout(flow.callback(), 1000); - - flow.queue(function(callback: Function) { - setTimeout(callback, 1000); - }); - flow.queue((callback: (err: any, res: string) => void) => { - callback(null, ''); - }); - - flow.wait(); -}); - -})(); - - -// Task timeouts -(function() { - -asyncblock(function(flow){ - setTimeout(flow.add({timeout: 1000, timeoutIsError: false}), 2000); - flow.wait(); //The fiber will yield here for 1 second, then continue - - //Code here will run -}); - -asyncblock(function(flow){ - flow.timeoutIsError = false; - - setTimeout(flow.add({timeout: 1000}), 2000); - flow.wait(); //The fiber will yield here for 1 second, then continue - - //Code here will run -}); - -})(); - diff --git a/types/asyncblock/index.d.ts b/types/asyncblock/index.d.ts deleted file mode 100644 index e848f509fb..0000000000 --- a/types/asyncblock/index.d.ts +++ /dev/null @@ -1,71 +0,0 @@ -// Type definitions for asyncblock 2.1.23 -// Project: https://github.com/scriby/asyncblock -// Definitions by: Hiroki Horiuchi -// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped - - - -declare function asyncblock(f: (flow: asyncblock.IFlow) => void, callback?: (err: any, res: T) => void): void; - -declare namespace asyncblock { - export function nostack(f: (flow: asyncblock.IFlow) => void, callback?: (err: any, res: T) => void): void; - - export interface IFlow { - add(responseFormat?: string[]): IExecuteFunction; - add(key: string, responseFormat?: string[]): IExecuteFunction; - add(key: number, responseFormat?: string[]): IExecuteFunction; - add(options: IFlowOptions): IExecuteFunction; - callback(responseFormat?: string[]): IExecuteFunction; - callback(key: string, responseFormat?: string[]): IExecuteFunction; - callback(key: number, responseFormat?: string[]): IExecuteFunction; - callback(options: IFlowOptions): IExecuteFunction; - wait(key?: string): T; - wait(key?: number): T; - - get(key: string): T; - set(key: string, responseFormat?: string[]): IExecuteFunction; - set(options: IFlowOptions): IExecuteFunction; - del(key: string): void; - - sync(task: any): T; - queue(toExecute: IExecuteFunction): void; - queue(key: string, toExecute: IExecuteFunction): void; - queue(key: number, toExecute: IExecuteFunction): void; - queue(responseFormat: string[], toExecute: IExecuteFunction): void; - queue(key: string, responseFormat: string[], toExecute: IExecuteFunction): void; - queue(key: number, responseFormat: string[], toExecute: IExecuteFunction): void; - queue(options: IFlowOptions, toExecute: IExecuteFunction): void; - doneAdding(): void; - forceWait(): T; - - maxParallel: number; - errorCallback: (err: any) => void; - taskTimeout: number; - timeoutIsError: boolean; - } - - export interface IFlowOptions { - ignoreError?: boolean; // default false - key?: string; // string | number - responseFormat?: string[]; - timeout?: number; - timeoutIsError?: boolean; - dontWait?: boolean; - firstArgIsError?: boolean; // default true - } - - export interface IExecuteFunction { - (err: any, res1: T1, res2: T2, res3: T3): any; - (err: any, res1: T1, res2: T2): any; - (err: any, res: T): any; - (err: any): any; - - // firstArgIsError === false - (res1: T1, res2: T2, res3: T3): any; - (res1: T1, res2: T2): any; - (res: T): any; - } - -} - -export = asyncblock; diff --git a/types/asyncblock/tsconfig.json b/types/asyncblock/tsconfig.json deleted file mode 100644 index c696706864..0000000000 --- a/types/asyncblock/tsconfig.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "compilerOptions": { - "module": "commonjs", - "lib": [ - "es6", - "dom" - ], - "noImplicitAny": true, - "noImplicitThis": true, - "strictNullChecks": false, - "strictFunctionTypes": true, - "baseUrl": "../", - "typeRoots": [ - "../" - ], - "types": [], - "noEmit": true, - "forceConsistentCasingInFileNames": true - }, - "files": [ - "index.d.ts", - "asyncblock-tests.ts" - ] -} \ No newline at end of file diff --git a/types/asyncblock/tslint.json b/types/asyncblock/tslint.json deleted file mode 100644 index a41bf5d19a..0000000000 --- a/types/asyncblock/tslint.json +++ /dev/null @@ -1,79 +0,0 @@ -{ - "extends": "dtslint/dt.json", - "rules": { - "adjacent-overload-signatures": false, - "array-type": false, - "arrow-return-shorthand": false, - "ban-types": false, - "callable-types": false, - "comment-format": false, - "dt-header": false, - "eofline": false, - "export-just-namespace": false, - "import-spacing": false, - "interface-name": false, - "interface-over-type-literal": false, - "jsdoc-format": false, - "max-line-length": false, - "member-access": false, - "new-parens": false, - "no-any-union": false, - "no-boolean-literal-compare": false, - "no-conditional-assignment": false, - "no-consecutive-blank-lines": false, - "no-construct": false, - "no-declare-current-package": false, - "no-duplicate-imports": false, - "no-duplicate-variable": false, - "no-empty-interface": false, - "no-for-in-array": false, - "no-inferrable-types": false, - "no-internal-module": false, - "no-irregular-whitespace": false, - "no-mergeable-namespace": false, - "no-misused-new": false, - "no-namespace": false, - "no-object-literal-type-assertion": false, - "no-padding": false, - "no-redundant-jsdoc": false, - "no-redundant-jsdoc-2": false, - "no-redundant-undefined": false, - "no-reference-import": false, - "no-relative-import-in-test": false, - "no-self-import": false, - "no-single-declare-module": false, - "no-string-throw": false, - "no-unnecessary-callback-wrapper": false, - "no-unnecessary-class": false, - "no-unnecessary-generics": false, - "no-unnecessary-qualifier": false, - "no-unnecessary-type-assertion": false, - "no-useless-files": false, - "no-var-keyword": false, - "no-var-requires": false, - "no-void-expression": false, - "no-trailing-whitespace": false, - "object-literal-key-quotes": false, - "object-literal-shorthand": false, - "one-line": false, - "one-variable-per-declaration": false, - "only-arrow-functions": false, - "prefer-conditional-expression": false, - "prefer-const": false, - "prefer-declare-function": false, - "prefer-for-of": false, - "prefer-method-signature": false, - "prefer-template": false, - "radix": false, - "semicolon": false, - "space-before-function-paren": false, - "space-within-parens": false, - "strict-export-declare-modifiers": false, - "trim-file": false, - "triple-equals": false, - "typedef-whitespace": false, - "unified-signatures": false, - "void-return": false, - "whitespace": false - } -}