node-gulp-4.0.2+~cs38.20.35/ 0000775 0000000 0000000 00000000000 14156670073 0015040 5 ustar 00root root 0000000 0000000 node-gulp-4.0.2+~cs38.20.35/.ci/ 0000775 0000000 0000000 00000000000 14156670073 0015511 5 ustar 00root root 0000000 0000000 node-gulp-4.0.2+~cs38.20.35/.ci/.azure-pipelines-steps.yml 0000664 0000000 0000000 00000002066 14156670073 0022566 0 ustar 00root root 0000000 0000000 steps:
- script: npm i -g npm@$(npm_version)
displayName: Use legacy npm version $(npm_version)
condition: ne(variables['npm_version'], '')
- task: NodeTool@0
inputs:
versionSpec: '$(node_version)'
displayName: Use Node $(node_version)
- script: npm install
displayName: npm install
- script: npm test
displayName: Run tests
- script: npm run coveralls
displayName: Run coveralls
env:
# Pretend to be AppVeyor for now
APPVEYOR: true
APPVEYOR_BUILD_NUMBER: $(Build.BuildNumber)
APPVEYOR_BUILD_ID: $(Agent.OS)_$(node_version)
APPVEYOR_REPO_COMMIT: $(Build.SourceVersion)
APPVEYOR_REPO_BRANCH: $(Build.SourceBranchName)
# Overwrite the AppVeyor Service Name
COVERALLS_SERVICE_NAME: Azure Pipelines
COVERALLS_REPO_TOKEN: $(COVERALLS_REPO_TOKEN_SECRET)
COVERALLS_PARALLEL: true
CI_PULL_REQUEST: $(System.PullRequest.PullRequestNumber)
- script: npm run azure-pipelines
displayName: Write tests to xml
- task: PublishTestResults@2
inputs:
testResultsFiles: '**/test.xunit'
condition: succeededOrFailed()
node-gulp-4.0.2+~cs38.20.35/.ci/.azure-pipelines.yml 0000664 0000000 0000000 00000004050 14156670073 0021425 0 ustar 00root root 0000000 0000000 trigger:
- master
- releases/*
jobs:
- job: Test_Linux
displayName: Run Tests on Linux
pool:
vmImage: "Ubuntu 16.04"
strategy:
matrix:
Node_v12:
node_version: 12
Node_v10:
node_version: 10
Node_v8:
node_version: 8
Node_v6:
node_version: 6
Node_v4:
node_version: 4
Node_v0_12:
node_version: 0.12
Node_v0_10:
node_version: 0.10
steps:
- template: .azure-pipelines-steps.yml
- job: Test_Windows
displayName: Run Tests on Windows
pool:
vmImage: vs2017-win2016
strategy:
matrix:
Node_v12:
node_version: 12
Node_v10:
node_version: 10
Node_v8:
node_version: 8
Node_v6:
node_version: 6
Node_v4:
node_version: 4
npm_version: 2
Node_v0_12:
node_version: 0.12
npm_version: 2
Node_v0_10:
node_version: 0.10
npm_version: 2
steps:
- template: .azure-pipelines-steps.yml
- job: Test_MacOS
displayName: Run Tests on MacOS
pool:
vmImage: macos-10.13
strategy:
matrix:
Node_v12:
node_version: 12
Node_v10:
node_version: 10
Node_v8:
node_version: 8
Node_v6:
node_version: 6
Node_v4:
node_version: 4
Node_v0_12:
node_version: 0.12
Node_v0_10:
node_version: 0.10
steps:
- template: .azure-pipelines-steps.yml
- job: Notify_Coveralls
displayName: Notify Coveralls that the parallel report is done
pool:
vmImage: "Ubuntu 16.04"
dependsOn:
- Test_Linux
- Test_Windows
- Test_MacOS
steps:
- script: curl -k https://coveralls.io/webhook?repo_token=$COVERALLS_REPO_TOKEN -d "payload[build_num]=$BUILD_NAME&payload[status]=done"
env:
COVERALLS_REPO_TOKEN: $(COVERALLS_REPO_TOKEN_SECRET)
BUILD_NAME: $(Build.BuildNumber)
node-gulp-4.0.2+~cs38.20.35/.editorconfig 0000664 0000000 0000000 00000000326 14156670073 0017516 0 ustar 00root root 0000000 0000000 # http://editorconfig.org
root = true
[*]
indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
end_of_line = lf
[*.md]
trim_trailing_whitespace = false
node-gulp-4.0.2+~cs38.20.35/.eslintrc 0000664 0000000 0000000 00000000030 14156670073 0016655 0 ustar 00root root 0000000 0000000 {
"extends": "gulp"
}
node-gulp-4.0.2+~cs38.20.35/.gitattributes 0000664 0000000 0000000 00000000016 14156670073 0017730 0 ustar 00root root 0000000 0000000 * text eol=lf
node-gulp-4.0.2+~cs38.20.35/.npmrc 0000664 0000000 0000000 00000000023 14156670073 0016153 0 ustar 00root root 0000000 0000000 package-lock=false
node-gulp-4.0.2+~cs38.20.35/.travis.yml 0000664 0000000 0000000 00000000213 14156670073 0017145 0 ustar 00root root 0000000 0000000 sudo: false
language: node_js
node_js:
- '12'
- '10'
- '8'
- '6'
- '4'
- '0.12'
- '0.10'
after_script:
- npm run coveralls
node-gulp-4.0.2+~cs38.20.35/LICENSE 0000664 0000000 0000000 00000002142 14156670073 0016044 0 ustar 00root root 0000000 0000000 The MIT License (MIT)
Copyright (c) 2015 Blaine Bublitz, Eric Schoffstall and other contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
node-gulp-4.0.2+~cs38.20.35/README.md 0000664 0000000 0000000 00000012214 14156670073 0016317 0 ustar 00root root 0000000 0000000
# async-done
[![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Azure Pipelines Build Status][azure-pipelines-image]][azure-pipelines-url] [![Travis Build Status][travis-image]][travis-url] [![AppVeyor Build Status][appveyor-image]][appveyor-url] [![Coveralls Status][coveralls-image]][coveralls-url] [![Gitter chat][gitter-image]][gitter-url]
Allows libraries to handle various caller provided asynchronous functions uniformly. Maps promises, observables, child processes and streams, and callbacks to callback style.
As async conventions evolve, it is useful to be able to deal with several different *styles* of async completion uniformly. With this module you can handle completion using a node-style callback, regardless of a return value that's a promise, observable, child process or stream.
## Usage
### Successful completion
```js
var asyncDone = require('async-done');
asyncDone(function(done){
// do async things
done(null, 2);
}, function(error, result){
// `error` will be null on successful execution of the first function.
// `result` will be the result from the first function.
});
```
### Failed completion
```js
var asyncDone = require('async-done');
asyncDone(function(done){
// do async things
done(new Error('Some Error Occurred'));
}, function(error, result){
// `error` will be an error from the first function.
// `result` will be undefined on failed execution of the first function.
});
```
## API
### `asyncDone(fn, callback)`
Takes a function to execute (`fn`) and a function to call on completion (`callback`).
#### `fn([done])`
Optionally takes a callback to call when async tasks are complete.
#### Completion and Error Resolution
* `Callback` (`done`) called
- Completion: called with null error
- Error: called with non-null error
* `Stream` or `EventEmitter` returned
- Completion: [end-of-stream][end-of-stream] module
- Error: [domains][domains]
- __Note:__ Only actual streams are supported, not faux-streams; Therefore, modules like [`event-stream`][event-stream] are not supported.
* `Child Process` returned
- Completion [end-of-stream][end-of-stream] module
- Error: [domains][domains]
* `Promise` returned
- Completion: [onFulfilled][promise-onfulfilled] method called
- Error: [onRejected][promise-onrejected] method called
* `Observable` (e.g. from [RxJS v5][rxjs5-observable] or [RxJS v4][rxjs5-observable]) returned
- Completion: [complete][rxjs5-observer-complete] method called
- Error: [error][rxjs5-observer-error] method called
__Warning:__ Sync tasks are __not supported__ and your function will never complete if the one of the above strategies is not used to signal completion. However, thrown errors will be caught by the domain.
#### `callback(error, result)`
If an error doesn't occur in the execution of the `fn` function, the `callback` method will receive the results as its second argument. Note: Some streams don't received any results.
If an error occurred in the execution of the `fn` function, The `callback` method will receive an error as its first argument.
Errors can be caused by:
* A thrown error
* An error passed to a `done` callback
* An `error` event emitted on a returned `Stream`, `EventEmitter` or `Child Process`
* A rejection of a returned `Promise` - If the `Promise` is not rejected with a value, we generate a new `Error`
* The `onError` handler being called on an `Observable`
## License
MIT
[downloads-image]: https://img.shields.io/npm/dm/async-done.svg
[npm-url]: https://www.npmjs.com/package/async-done
[npm-image]: https://img.shields.io/npm/v/async-done.svg
[azure-pipelines-url]: https://dev.azure.com/gulpjs/gulp/_build/latest?definitionId=6&branchName=master
[azure-pipelines-image]: https://dev.azure.com/gulpjs/gulp/_apis/build/status/async-done?branchName=master
[travis-url]: https://travis-ci.org/gulpjs/async-done
[travis-image]: https://img.shields.io/travis/gulpjs/async-done.svg?label=travis-ci
[appveyor-url]: https://ci.appveyor.com/project/gulpjs/async-done
[appveyor-image]: https://img.shields.io/appveyor/ci/gulpjs/async-done.svg?label=appveyor
[coveralls-url]: https://coveralls.io/r/gulpjs/async-done
[coveralls-image]: https://img.shields.io/coveralls/gulpjs/async-done/master.svg
[gitter-url]: https://gitter.im/gulpjs/gulp
[gitter-image]: https://badges.gitter.im/gulpjs/gulp.svg
[end-of-stream]: https://www.npmjs.com/package/end-of-stream
[domains]: http://nodejs.org/api/domain.html
[event-stream]: https://github.com/dominictarr/event-stream
[promise-onfulfilled]: http://promisesaplus.com/#point-26
[promise-onrejected]: http://promisesaplus.com/#point-30
[rx4-observable]: https://github.com/Reactive-Extensions/RxJS/blob/master/doc/api/core/observable.md
[rxjs5-observable]: http://reactivex.io/rxjs/class/es6/Observable.js~Observable.html
[rxjs5-observer-complete]: http://reactivex.io/rxjs/class/es6/MiscJSDoc.js~ObserverDoc.html#instance-method-complete
[rxjs5-observer-error]: http://reactivex.io/rxjs/class/es6/MiscJSDoc.js~ObserverDoc.html#instance-method-error
node-gulp-4.0.2+~cs38.20.35/appveyor.yml 0000664 0000000 0000000 00000001252 14156670073 0017430 0 ustar 00root root 0000000 0000000 # http://www.appveyor.com/docs/appveyor-yml
# http://www.appveyor.com/docs/lang/nodejs-iojs
environment:
matrix:
# node.js
- nodejs_version: "0.10"
- nodejs_version: "0.12"
- nodejs_version: "4"
- nodejs_version: "6"
- nodejs_version: "8"
- nodejs_version: "10"
- nodejs_version: "12"
platform:
- x86
- x64
install:
# https://www.appveyor.com/docs/lang/nodejs-iojs/#installing-any-version-of-nodejs-or-iojs
- ps: Update-NodeJsInstallation (Get-NodeJsLatestBuild $env:nodejs_version) $env:PLATFORM
- npm install
test_script:
- node --version
- npm --version
- cmd: npm test
build: off
# build version format
version: "{build}"
node-gulp-4.0.2+~cs38.20.35/index.d.ts 0000664 0000000 0000000 00000006673 14156670073 0016755 0 ustar 00root root 0000000 0000000 /**
* Notes about these type definitions:
*
* - Callbacks returning multiple completion values using multiple arguments are not supported by these types.
* Prefer to use Node's style by grouping your values in a single object or array.
* Support for this kind of callback is blocked by Microsoft/TypeScript#5453
*
* - For ease of use, `asyncDone` lets you pass callback functions with a result type `T` instead of `T | undefined`.
* This matches Node's types but can lead to unsound code being typechecked.
*
* The following code typechecks but fails at runtime:
* ```typescript
* async function getString(): Promise {
* return "Hello, World!";
* }
*
* async function evilGetString(): Promise {
* throw new Error("Hello, World!");
* }
*
* function cb(err: Error | null, result: string): void {
* // This is unsound because `result` is `undefined` when `err` is not `null`.
* console.log(result.toLowerCase());
* }
*
* asyncDone(getString, cb); // Prints `hello, world!`
* asyncDone(evilGetString, cb); // Runtime error: `TypeError: Cannot read property 'toLowerCase' of undefined`
* ```
*
* Enforcing stricter callbacks would require developers to use `result?: string` and assert the existence
* of the result either by checking it directly or using the `!` assertion operator after testing for errors.
* ```typescript
* function stricterCb1(err: Error | null, result?: string): void {
* if (err !== null) {
* console.error(err);
* return;
* }
* console.log(result!.toLowerCase());
* }
*
* function stricterCb2(err: Error | null, result?: string): void {
* if (result === undefined) {
* console.error("Undefined result. Error:);
* console.error(err);
* return;
* }
* console.log(result.toLowerCase());
* }
* ```
*/
import { ChildProcess } from "child_process";
import { EventEmitter } from "events";
import { Stream } from "stream";
declare namespace asyncDone {
/**
* Represents a callback function used to signal the completion of a
* task without any result value.
*/
type VoidCallback = (err: Error | null) => void;
/**
* Represents a callback function used to signal the completion of a
* task with a single result value.
*/
interface Callback {
(err: null, result: T): void;
// Use `result?: T` or `result: undefined` to require the consumer to assert the existence of the result
// (even in case of success). See comment at the top of the file.
(err: Error, result?: any): void;
}
/**
* Minimal `Observable` interface compatible with `async-done`.
*
* @see https://github.com/ReactiveX/rxjs/blob/c3c56867eaf93f302ac7cd588034c7d8712f2834/src/internal/Observable.ts#L77
*/
interface Observable {
subscribe(next?: (value: T) => void, error?: (error: any) => void, complete?: () => void): any;
}
/**
* Represents an async operation.
*/
export type AsyncTask =
((done: VoidCallback) => void)
| ((done: Callback) => void)
| (() => ChildProcess | EventEmitter | Observable | PromiseLike | Stream);
}
/**
* Takes a function to execute (`fn`) and a function to call on completion (`callback`).
*
* @param fn Function to execute.
* @param callback Function to call on completion.
*/
declare function asyncDone(fn: asyncDone.AsyncTask, callback: asyncDone.Callback): void;
export = asyncDone;
node-gulp-4.0.2+~cs38.20.35/index.js 0000664 0000000 0000000 00000003142 14156670073 0016505 0 ustar 00root root 0000000 0000000 'use strict';
var domain = require('domain');
var eos = require('end-of-stream');
var p = require('process-nextick-args');
var once = require('once');
var exhaust = require('stream-exhaust');
var eosConfig = {
error: false,
};
function rethrowAsync(err) {
process.nextTick(rethrow);
function rethrow() {
throw err;
}
}
function tryCatch(fn, args) {
try {
return fn.apply(null, args);
} catch (err) {
rethrowAsync(err);
}
}
function asyncDone(fn, cb) {
cb = once(cb);
var d = domain.create();
d.once('error', onError);
var domainBoundFn = d.bind(fn);
function done() {
d.removeListener('error', onError);
d.exit();
return tryCatch(cb, arguments);
}
function onSuccess(result) {
done(null, result);
}
function onError(error) {
if (!error) {
error = new Error('Promise rejected without Error');
}
done(error);
}
function asyncRunner() {
var result = domainBoundFn(done);
function onNext(state) {
onNext.state = state;
}
function onCompleted() {
onSuccess(onNext.state);
}
if (result && typeof result.on === 'function') {
// Assume node stream
d.add(result);
eos(exhaust(result), eosConfig, done);
return;
}
if (result && typeof result.subscribe === 'function') {
// Assume RxJS observable
result.subscribe(onNext, onError, onCompleted);
return;
}
if (result && typeof result.then === 'function') {
// Assume promise
result.then(onSuccess, onError);
return;
}
}
p.nextTick(asyncRunner);
}
module.exports = asyncDone;
node-gulp-4.0.2+~cs38.20.35/package.json 0000664 0000000 0000000 00000003342 14156670073 0017330 0 ustar 00root root 0000000 0000000 {
"name": "async-done",
"version": "1.3.2",
"description": "Allows libraries to handle various caller provided asynchronous functions uniformly. Maps promises, observables, child processes and streams, and callbacks to callback style.",
"author": "Gulp Team (https://gulpjs.com/)",
"contributors": [
"Blaine Bublitz ",
"Pawel Kozlowski ",
"Matthew Podwysocki ",
"Charles Samborski "
],
"repository": "gulpjs/async-done",
"license": "MIT",
"engines": {
"node": ">= 0.10"
},
"main": "index.js",
"types": "index.d.ts",
"files": [
"index.js",
"index.d.ts",
"LICENSE"
],
"scripts": {
"lint": "eslint .",
"pretest": "npm run lint",
"test": "nyc mocha --async-only",
"test-types": "tsc -p test/types",
"azure-pipelines": "nyc mocha --async-only --reporter xunit -O output=test.xunit",
"coveralls": "nyc report --reporter=text-lcov | coveralls"
},
"dependencies": {
"end-of-stream": "^1.1.0",
"once": "^1.3.2",
"process-nextick-args": "^2.0.0",
"stream-exhaust": "^1.0.1"
},
"devDependencies": {
"@types/node": "^9.3.0",
"coveralls": "github:phated/node-coveralls#2.x",
"eslint": "^2.13.1",
"eslint-config-gulp": "^3.0.1",
"expect": "^1.20.2",
"mocha": "^3.0.0",
"nyc": "^10.3.2",
"pumpify": "^1.3.6",
"rxjs": "^5.5.6",
"through2": "^2.0.0",
"typescript": "^2.6.2",
"when": "^3.7.3"
},
"keywords": [
"promises",
"callbacks",
"observables",
"streams",
"end",
"completion",
"complete",
"finish",
"done",
"async",
"error handling"
]
}
node-gulp-4.0.2+~cs38.20.35/test/ 0000775 0000000 0000000 00000000000 14156670073 0016017 5 ustar 00root root 0000000 0000000 node-gulp-4.0.2+~cs38.20.35/test/.eslintrc 0000664 0000000 0000000 00000000035 14156670073 0017641 0 ustar 00root root 0000000 0000000 {
"extends": "gulp/test"
}
node-gulp-4.0.2+~cs38.20.35/test/arguments.js 0000664 0000000 0000000 00000000574 14156670073 0020370 0 ustar 00root root 0000000 0000000 'use strict';
var expect = require('expect');
var asyncDone = require('../');
function twoArg(cb) {
cb(null, 1, 2);
}
describe('arguments', function() {
it('passes all arguments to the completion callback', function(done) {
asyncDone(twoArg, function(err, arg1, arg2) {
expect(arg1).toEqual(1);
expect(arg2).toEqual(2);
done(err);
});
});
});
node-gulp-4.0.2+~cs38.20.35/test/callbacks.js 0000664 0000000 0000000 00000002227 14156670073 0020277 0 ustar 00root root 0000000 0000000 'use strict';
var expect = require('expect');
var asyncDone = require('../');
function success(cb) {
cb(null, 2);
}
function failure(cb) {
cb(new Error('Callback Error'));
}
function neverDone() {
return 2;
}
describe('callbacks', function() {
it('should handle a successful callback', function(done) {
asyncDone(success, function(err, result) {
expect(result).toEqual(2);
done(err);
});
});
it('should handle an errored callback', function(done) {
asyncDone(failure, function(err) {
expect(err).toBeAn(Error);
done();
});
});
it('a function that takes an argument but never calls callback', function(done) {
asyncDone(neverDone, function() {
done(new Error('Callback called'));
});
setTimeout(function() {
done();
}, 1000);
});
it('should not handle error if something throws inside the callback', function(done) {
var d = require('domain').create();
d.on('error', function(err) {
expect(err).toBeAn(Error);
done();
});
d.run(function() {
asyncDone(success, function() {
throw new Error('Thrown Error');
});
});
});
});
node-gulp-4.0.2+~cs38.20.35/test/child_processes.js 0000664 0000000 0000000 00000002075 14156670073 0021532 0 ustar 00root root 0000000 0000000 'use strict';
var expect = require('expect');
var cp = require('child_process');
var asyncDone = require('../');
function execSuccess() {
return cp.exec('echo hello world');
}
function execFail() {
return cp.exec('foo-bar-baz hello world');
}
function spawnSuccess() {
return cp.spawn('echo', ['hello world']);
}
function spawnFail() {
return cp.spawn('foo-bar-baz', ['hello world']);
}
describe('child processes', function() {
it('should handle successful exec', function(done) {
asyncDone(execSuccess, function(err) {
expect(err).toNotBeAn(Error);
done();
});
});
it('should handle failing exec', function(done) {
asyncDone(execFail, function(err) {
expect(err).toBeAn(Error);
done();
});
});
it('should handle successful spawn', function(done) {
asyncDone(spawnSuccess, function(err) {
expect(err).toNotBeAn(Error);
done();
});
});
it('should handle failing spawn', function(done) {
asyncDone(spawnFail, function(err) {
expect(err).toBeAn(Error);
done();
});
});
});
node-gulp-4.0.2+~cs38.20.35/test/observables.js 0000664 0000000 0000000 00000001671 14156670073 0020671 0 ustar 00root root 0000000 0000000 'use strict';
var expect = require('expect');
var asyncDone = require('../');
var Observable = require('rxjs').Observable;
function success() {
return Observable.empty();
}
function successValue() {
// This corresponds to `Observable.return(42);` in RxJS 4
return Observable.of(42);
}
function failure() {
return Observable.throw(new Error('Observable error'));
}
describe('observables', function() {
it('should handle a finished observable', function(done) {
asyncDone(success, function(err, result) {
expect(result).toEqual(undefined);
done(err);
});
});
it('should handle a finished observable with value', function(done) {
asyncDone(successValue, function(err, result) {
expect(result).toEqual(42);
done(err);
});
});
it('should handle an errored observable', function(done) {
asyncDone(failure, function(err) {
expect(err).toBeAn(Error);
done();
});
});
});
node-gulp-4.0.2+~cs38.20.35/test/promises.js 0000664 0000000 0000000 00000002334 14156670073 0020220 0 ustar 00root root 0000000 0000000 'use strict';
var domain = require('domain');
var expect = require('expect');
var when = require('when');
var asyncDone = require('../');
function success() {
return when.resolve(2);
}
function failure() {
return when.reject(new Error('Promise Error'));
}
function rejectNoError() {
return when.reject();
}
describe('promises', function() {
it('should handle a resolved promise', function(done) {
asyncDone(success, function(err, result) {
expect(result).toEqual(2);
done(err);
});
});
it('should handle a rejected promise', function(done) {
asyncDone(failure, function(err) {
expect(err).toBeAn(Error);
done();
});
});
it('properly errors when rejected without an error', function(done) {
asyncDone(rejectNoError, function(err) {
expect(err).toExist();
expect(err).toBeAn(Error);
done();
});
});
it('does not swallow thrown errors in callback', function(done) {
var d = domain.create();
d.once('error', function(err) {
expect(err).toExist();
expect(err.message).toContain('Boom');
done();
});
d.run(function() {
asyncDone(success, function() {
throw new Error('Boom');
});
});
});
});
node-gulp-4.0.2+~cs38.20.35/test/streams.js 0000664 0000000 0000000 00000004016 14156670073 0020034 0 ustar 00root root 0000000 0000000 'use strict';
var expect = require('expect');
var fs = require('fs');
var path = require('path');
var through = require('through2');
var pumpify = require('pumpify');
var asyncDone = require('../');
var exists = path.join(__dirname, '../.gitignore');
var notExists = path.join(__dirname, '../not_exists');
var EndStream = through.ctor(function(chunk, enc, cb) {
this.push(chunk);
cb();
}, function(cb) {
this.emit('end', 2);
cb();
});
function success() {
var read = fs.createReadStream(exists);
return read.pipe(new EndStream());
}
function failure() {
var read = fs.createReadStream(notExists);
return read.pipe(new EndStream());
}
function withErr(chunk, _, cb) {
cb(new Error('Fail'));
}
function pumpifyError() {
var read = fs.createReadStream(exists);
var pipeline = pumpify(
through(),
through(withErr),
through()
);
return read.pipe(pipeline);
}
function unpiped() {
return fs.createReadStream(exists);
}
describe('streams', function() {
it('should handle a successful stream', function(done) {
asyncDone(success, function(err) {
expect(err).toNotBeAn(Error);
done();
});
});
it('should handle an errored stream', function(done) {
asyncDone(failure, function(err) {
expect(err).toBeAn(Error);
done();
});
});
it('should handle an errored pipeline', function(done) {
asyncDone(pumpifyError, function(err) {
expect(err).toBeAn(Error);
expect(err.message).toNotBe('premature close');
done();
});
});
it('handle a returned stream and cb by only calling callback once', function(done) {
asyncDone(function(cb) {
return success().on('end', function() {
cb(null, 3);
});
}, function(err, result) {
expect(err).toNotBeAn(Error);
expect(result).toEqual(3); // To know we called the callback
done();
});
});
it('consumes an unpiped readable stream', function(done) {
asyncDone(unpiped, function(err) {
expect(err).toNotBeAn(Error);
done();
});
});
});
node-gulp-4.0.2+~cs38.20.35/test/types/ 0000775 0000000 0000000 00000000000 14156670073 0017163 5 ustar 00root root 0000000 0000000 node-gulp-4.0.2+~cs38.20.35/test/types/callback.ts 0000664 0000000 0000000 00000002274 14156670073 0021274 0 ustar 00root root 0000000 0000000 import asyncDone, { Callback } from "async-done";
function success(cb: Callback): void {
cb(null, 2);
}
function failure(cb: Callback): void {
cb(new Error("Callback Error"));
}
function neverDone(): number {
return 2;
}
// `success` and stricter callback
asyncDone(success, function (err: Error | null, result?: number): void {
console.log("Done");
});
// The following code fails to compile as expected:
// asyncDone(success, function (err: Error | null, result?: string): void {
// console.log("Done");
// });
// `success` and unsound callback
asyncDone(success, function (err: Error | null, result: number): void {
console.log("Done");
});
// `failure` and stricter callback
asyncDone(failure, function (err: Error | null, result?: number): void {
console.log("Done");
});
// `failure` and unsound callback
asyncDone(failure, function (err: Error | null, result: number): void {
console.log("Done");
});
// I don't think TS is currently able to prevent the current code from compiling
// (`neverDone` matches with `(done: VoidCallback) => void` for example)
// asyncDone(neverDone, function(err: Error | null, result?: number): void {
// console.log("Done");
// });
node-gulp-4.0.2+~cs38.20.35/test/types/child_processes.ts 0000664 0000000 0000000 00000000622 14156670073 0022704 0 ustar 00root root 0000000 0000000 import asyncDone from "async-done";
import cp from "child_process";
function success(): cp.ChildProcess {
return cp.exec("echo hello world");
}
function failure(): cp.ChildProcess {
return cp.exec("foo-bar-baz hello world");
}
asyncDone(success, function (err: Error | null): void {
console.log("Done");
});
asyncDone(failure, function (err: Error | null): void {
console.log("Done");
});
node-gulp-4.0.2+~cs38.20.35/test/types/observables.ts 0000664 0000000 0000000 00000002375 14156670073 0022051 0 ustar 00root root 0000000 0000000 import asyncDone from "async-done";
import { Observable } from "rxjs/Observable";
import 'rxjs/add/observable/empty';
import 'rxjs/add/observable/of';
function success(): Observable {
return Observable.empty();
}
function successValue(): Observable {
return Observable.of(42);
}
function failure(): Observable {
return Observable.throw(new Error("Observable error"));
}
// `success` callback
asyncDone(success, function (err: Error | null): void {
console.log("Done");
});
// The following code fails to compile as expected (`undefined` is not assignable to `number`):
// asyncDone(success, function (err: Error | null, result: number): void {
// console.log("Done");
// });
// `successValue` and stricter callback
asyncDone(successValue, function (err: Error | null, result?: number): void {
console.log("Done");
});
// `successValue` and unsound callback
asyncDone(successValue, function (err: Error | null, result: number): void {
console.log("Done");
});
// `failure` and stricter callback
asyncDone(failure, function (err: Error | null, result?: number): void {
console.log("Done");
});
// `failure` and unsound callback
asyncDone(failure, function (err: Error | null, result: number): void {
console.log("Done");
});
node-gulp-4.0.2+~cs38.20.35/test/types/promises.ts 0000664 0000000 0000000 00000001620 14156670073 0021373 0 ustar 00root root 0000000 0000000 import asyncDone from "async-done";
function success(): Promise {
return Promise.resolve(2);
}
function failure(): Promise {
return Promise.reject(new Error("Promise Error"));
}
// `successValue` and stricter callback
asyncDone(success, function (err: Error | null, result?: number): void {
console.log("Done");
});
// The following code fails to compile as expected:
// asyncDone(success, function (err: Error | null, result?: string): void {
// console.log("Done");
// });
// `successValue` and unsound callback
asyncDone(success, function (err: Error | null, result: number): void {
console.log("Done");
});
// `failure` and stricter callback
asyncDone(failure, function (err: Error | null, result?: number): void {
console.log("Done");
});
// `failure` and unsound callback
asyncDone(failure, function (err: Error | null, result: number): void {
console.log("Done");
});
node-gulp-4.0.2+~cs38.20.35/test/types/streams.ts 0000664 0000000 0000000 00000000567 14156670073 0021221 0 ustar 00root root 0000000 0000000 import asyncDone from "async-done";
import { Readable, Stream } from "stream";
function streamSuccess(): Stream {
return new Stream();
}
function streamFail(): Stream {
return new Stream();
}
asyncDone(streamSuccess, function (err: Error | null): void {
console.log("Done");
});
asyncDone(streamFail, function (err: Error | null): void {
console.log("Done");
});
node-gulp-4.0.2+~cs38.20.35/test/types/tsconfig.json 0000664 0000000 0000000 00000003027 14156670073 0021674 0 ustar 00root root 0000000 0000000 {
"compilerOptions": {
"allowJs": false,
"allowSyntheticDefaultImports": true,
"allowUnreachableCode": false,
"allowUnusedLabels": false,
"alwaysStrict": true,
"baseUrl": "../..",
"charset": "utf8",
"checkJs": false,
"declaration": true,
"disableSizeLimit": false,
"downlevelIteration": false,
"emitBOM": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"forceConsistentCasingInFileNames": true,
"importHelpers": false,
"inlineSourceMap": false,
"inlineSources": false,
"isolatedModules": false,
"lib": [
"es2017"
],
"locale": "en-us",
"module": "commonjs",
"moduleResolution": "node",
"newLine": "lf",
"noEmit": true,
"noEmitHelpers": false,
"noEmitOnError": true,
"noErrorTruncation": true,
"noFallthroughCasesInSwitch": true,
"noImplicitAny": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noStrictGenericChecks": false,
"noUnusedLocals": false,
"noUnusedParameters": false,
"noLib": false,
"noResolve": false,
"paths": {
"async-done": [
"index.d.ts"
]
},
"preserveConstEnums": true,
"removeComments": false,
"rootDir": "",
"skipLibCheck": false,
"sourceMap": true,
"strict": true,
"strictNullChecks": true,
"suppressExcessPropertyErrors": false,
"suppressImplicitAnyIndexErrors": false,
"target": "es2017",
"traceResolution": false
},
"include": [
"./**/*.ts"
],
"exclude": []
}
node-gulp-4.0.2+~cs38.20.35/test/types/various.ts 0000664 0000000 0000000 00000000334 14156670073 0021223 0 ustar 00root root 0000000 0000000 import asyncDone, {AsyncTask, VoidCallback} from "async-done";
// Do not error if the return value is not `void`.
const fn: AsyncTask = (cb: VoidCallback): NodeJS.Timer => setTimeout(cb, 1000);
asyncDone(fn, () => {});