taskgroup
Advanced tools
Comparing version 5.0.1 to 5.0.2
'use strict'; | ||
var _require = require('./lib/task'); | ||
var _require = require('./lib/task'), | ||
Task = _require.Task; | ||
var Task = _require.Task; | ||
var _require2 = require('./lib/taskgroup'), | ||
TaskGroup = _require2.TaskGroup; | ||
var _require2 = require('./lib/taskgroup'); | ||
var TaskGroup = _require2.TaskGroup; | ||
module.exports = { Task: Task, TaskGroup: TaskGroup }; |
'use strict'; | ||
/** | ||
Base class containing common functionality for {@link Task} and {@link TaskGroup}. | ||
@class BaseInterface | ||
@extends EventEmitter | ||
@constructor | ||
@access private | ||
*/ | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
@@ -13,11 +22,2 @@ | ||
/** | ||
Base class containing common functionality for {@link Task} and {@link TaskGroup}. | ||
@class BaseInterface | ||
@extends EventEmitter | ||
@constructor | ||
@access private | ||
*/ | ||
var BaseInterface = function (_require$EventEmitter) { | ||
@@ -62,5 +62,4 @@ _inherits(BaseInterface, _require$EventEmitter); | ||
// Allow extensions of this class to prepare the class instance before anything else fires | ||
var _this = _possibleConstructorReturn(this, (BaseInterface.__proto__ || Object.getPrototypeOf(BaseInterface)).call(this)); | ||
var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(BaseInterface).call(this)); | ||
if (_this.prepare) { | ||
@@ -214,7 +213,7 @@ _this.prepare(); | ||
// Fetch | ||
var names = [];var _config = this.config; | ||
var name = _config.name; | ||
var parent = _config.parent; | ||
var nameSeparator = _config.nameSeparator; | ||
var names = [], | ||
_config = this.config, | ||
name = _config.name, | ||
parent = _config.parent, | ||
nameSeparator = _config.nameSeparator; | ||
if (parent) names.push.apply(names, _toConsumableArray(parent.names)); | ||
@@ -221,0 +220,0 @@ if (name !== false) names.push(this.name); |
@@ -0,5 +1,8 @@ | ||
/* eslint no-extra-parens:0 func-style:0 */ | ||
'use strict'; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; }; | ||
// Imports | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
@@ -15,14 +18,9 @@ | ||
/* eslint no-extra-parens:0 func-style:0 */ | ||
// Imports | ||
var _require = require('./interface'), | ||
BaseInterface = _require.BaseInterface; | ||
var _require = require('./interface'); | ||
var _require2 = require('./util'), | ||
queue = _require2.queue, | ||
domain = _require2.domain; | ||
var BaseInterface = _require.BaseInterface; | ||
var _require2 = require('./util'); | ||
var queue = _require2.queue; | ||
var domain = _require2.domain; | ||
var ambi = require('ambi'); | ||
@@ -293,4 +291,3 @@ var extendr = require('extendr'); | ||
// State defaults | ||
var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(Task).call(this)); | ||
var _this = _possibleConstructorReturn(this, (Task.__proto__ || Object.getPrototypeOf(Task)).call(this)); | ||
// Initialise BaseInterface | ||
@@ -571,3 +568,2 @@ | ||
var taskDomain = this.state.taskDomain; | ||
var useDomains = this.config.domain !== false; | ||
var exitMethod = this.itemCompletionCallback.bind(this); | ||
@@ -574,0 +570,0 @@ var method = this.config.method; |
@@ -0,5 +1,8 @@ | ||
/* eslint no-extra-parens:0 */ | ||
'use strict'; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; }; | ||
// Imports | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
@@ -15,18 +18,12 @@ | ||
/* eslint no-extra-parens:0 */ | ||
// Imports | ||
var _require = require('./interface'), | ||
BaseInterface = _require.BaseInterface; | ||
var _require = require('./interface'); | ||
var _require2 = require('./task'), | ||
Task = _require2.Task; | ||
var BaseInterface = _require.BaseInterface; | ||
var _require3 = require('./util'), | ||
queue = _require3.queue, | ||
ensureArray = _require3.ensureArray; | ||
var _require2 = require('./task'); | ||
var Task = _require2.Task; | ||
var _require3 = require('./util'); | ||
var queue = _require3.queue; | ||
var ensureArray = _require3.ensureArray; | ||
var extendr = require('extendr'); | ||
@@ -211,5 +208,5 @@ var eachr = require('eachr'); | ||
get: function get() { | ||
var _config = this.config; | ||
var storeResult = _config.storeResult; | ||
var destroyOnceDone = _config.destroyOnceDone; | ||
var _config = this.config, | ||
storeResult = _config.storeResult, | ||
destroyOnceDone = _config.destroyOnceDone; | ||
@@ -484,5 +481,4 @@ return storeResult == null ? destroyOnceDone : storeResult !== false; | ||
// Prepare | ||
var _this = _possibleConstructorReturn(this, (TaskGroup.__proto__ || Object.getPrototypeOf(TaskGroup)).call(this)); | ||
var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(TaskGroup).call(this)); | ||
if (_this.prepare) { | ||
@@ -747,3 +743,3 @@ _this.prepare.apply(_this, arguments); | ||
value: function addMethod(method) { | ||
var opts = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; | ||
var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
@@ -787,6 +783,5 @@ method = method.bind(this); // run the taskgroup method on the group, rather than itself | ||
parent: this | ||
}; | ||
// Extract | ||
var nestedTaskGroupConfig = this.config.nestedTaskGroupConfig; | ||
// Extract | ||
};var nestedTaskGroupConfig = this.config.nestedTaskGroupConfig; | ||
var nestedTaskConfig = this.config.nestedTaskConfig; | ||
@@ -1095,2 +1090,3 @@ var emitNestedEvents = this.config.emitNestedEvents; | ||
// Fire the next items | ||
/* eslint no-constant-condition:0 */ | ||
while (true) { | ||
@@ -1097,0 +1093,0 @@ var item = this.fireNextItem(); |
@@ -0,5 +1,6 @@ | ||
/* eslint no-extra-parens:0 */ | ||
'use strict'; | ||
/* eslint no-extra-parens:0 */ | ||
// Domains are crippled in the browser and on node 0.8, so don't use domains in those environments | ||
var domain = process.browser || process.versions.node.substr(0, 3) === '0.8' ? null : require('domain'); | ||
@@ -6,0 +7,0 @@ |
186
HISTORY.md
# History | ||
## v5.0.2 2018 July 13 | ||
- Updated base files using [boundation](https://github.com/bevry/boundation) | ||
- Updated dependencies | ||
## v5.0.1 2016 June 13 | ||
@@ -8,65 +12,65 @@ - Added `clear` to `clearRemaining` alias for backwards compatibility between v4 and v5 | ||
- Changes to be impressed by: | ||
- Dramatic performance improvements | ||
- Improved performance of 10,000 tasks from 13 seconds to 1 seconds | ||
- Improved memory footprint of 10,000 tasks from 130MB to 4MB (taken during completion event) | ||
- Code has moved from CoffeeScript to ESNext | ||
- Documentation is now powered by JSDoc | ||
- Module is published with [Editions](https://github.com/bevry/editions) | ||
- Dramatic performance improvements | ||
- Improved performance of 10,000 tasks from 13 seconds to 1 seconds | ||
- Improved memory footprint of 10,000 tasks from 130MB to 4MB (taken during completion event) | ||
- Code has moved from CoffeeScript to ESNext | ||
- Documentation is now powered by JSDoc | ||
- Module is published with [Editions](https://github.com/bevry/editions) | ||
- Changes to be cautious about: | ||
- Packaging: | ||
- `require('taskgroup')` is no longer the TaskGroup class, you must again do `require('taskgroup').TaskGroup` | ||
- It was too difficult to handle this across multiple environments without polluting scopes | ||
- Task and TaskGroup: | ||
- Once done, the item is now destroyed by default via the `destroyOnceDone` configuration option | ||
- This means to add tasks to an already completed TaskGroup, you will need to set `destroyOnceDone` to `false` | ||
- This will be a silent problem, unless coupled with a `pauseOnError`, `onError` or `onExit` deprecation error | ||
- Running and completed tasks are no longer stored | ||
- Completed items are now destroyed by default via TaskGroup's `destroyDoneItems` configuration option | ||
- If you wish to store them, use the event listeners and disable `destroyDoneItems` | ||
- `destroy()` now operates instantly, including removing all event listeners | ||
- So if you did `.done().destroy().done()` the first done listener would be discarded | ||
- Removed `exit()` method and `exit` configuration option | ||
- They were complex, ambiguous, and undocumented | ||
- `errorOnExcessCompletions` and `destroyOnceDone` configuration options are now provided | ||
- Replaced `onError` and `pauseOnError` configuration options with `abortOnError` for better clarity | ||
- Having two or more configuration options for this ability was overly complex | ||
- Removed `sync` configuration option | ||
- It was complex and only had one use case, which turned out was [better accomplished without it](https://github.com/bevry/safeps/releases/tag/v6.2.0) | ||
- Renamed `includeInResults` configuration option to `storeResult` with improved functionality | ||
- If `destroyOnceDone` is `true`, `storeResult` will default to `false` | ||
- `done()`, `onceDone()`, and `whenDone()` now only listen for upcoming completions, rather than past | ||
- Listening for past completions was too complex and could never guarantee consistent results | ||
- `timeout` configuration option has been removed | ||
- It is actually best and easily accomplished by your own task methods | ||
- Removed configuration options will throw deprecation errors to ease migration | ||
- TaskGroup: | ||
- `results` state property renamed to `result` | ||
- `addGroup()` method is now `addTaskGroup()`, alias provided | ||
- Split `nestedConfig` configuration option into `nestedTaskConfig` and `nestedTaskGroupConfig` | ||
- Packaging: | ||
- `require('taskgroup')` is no longer the TaskGroup class, you must again do `require('taskgroup').TaskGroup` | ||
- It was too difficult to handle this across multiple environments without polluting scopes | ||
- Task and TaskGroup: | ||
- Once done, the item is now destroyed by default via the `destroyOnceDone` configuration option | ||
- This means to add tasks to an already completed TaskGroup, you will need to set `destroyOnceDone` to `false` | ||
- This will be a silent problem, unless coupled with a `pauseOnError`, `onError` or `onExit` deprecation error | ||
- Running and completed tasks are no longer stored | ||
- Completed items are now destroyed by default via TaskGroup's `destroyDoneItems` configuration option | ||
- If you wish to store them, use the event listeners and disable `destroyDoneItems` | ||
- `destroy()` now operates instantly, including removing all event listeners | ||
- So if you did `.done().destroy().done()` the first done listener would be discarded | ||
- Removed `exit()` method and `exit` configuration option | ||
- They were complex, ambiguous, and undocumented | ||
- `errorOnExcessCompletions` and `destroyOnceDone` configuration options are now provided | ||
- Replaced `onError` and `pauseOnError` configuration options with `abortOnError` for better clarity | ||
- Having two or more configuration options for this ability was overly complex | ||
- Removed `sync` configuration option | ||
- It was complex and only had one use case, which turned out was [better accomplished without it](https://github.com/bevry/safeps/releases/tag/v6.2.0) | ||
- Renamed `includeInResults` configuration option to `storeResult` with improved functionality | ||
- If `destroyOnceDone` is `true`, `storeResult` will default to `false` | ||
- `done()`, `onceDone()`, and `whenDone()` now only listen for upcoming completions, rather than past | ||
- Listening for past completions was too complex and could never guarantee consistent results | ||
- `timeout` configuration option has been removed | ||
- It is actually best and easily accomplished by your own task methods | ||
- Removed configuration options will throw deprecation errors to ease migration | ||
- TaskGroup: | ||
- `results` state property renamed to `result` | ||
- `addGroup()` method is now `addTaskGroup()`, alias provided | ||
- Split `nestedConfig` configuration option into `nestedTaskConfig` and `nestedTaskGroupConfig` | ||
- Changes to be aware of: | ||
- Task and TaskGroup: | ||
- `started` event has been split into `pending` and `running` events for more accurate semantics | ||
- Less used public APIs have now been marked as `private` or `public` depending on their use cases | ||
- `getNames` method has been replaced by just `names` getter, which has its own `toString()` method that makes use of the `nameSeparator` configuration option, alias provided | ||
- `getConfig()` method now `config` getter, alias provided | ||
- `isCompleted() method now `completed` getter, alias provided | ||
- `hasStarted()` method now `started` getter, alias provided | ||
- TaskGroup: | ||
- `getTotalItems()` method now `totalItems` getter, alias provided | ||
- `getItemTotals()` method now `itemTotals getter, alias provided | ||
- Task: | ||
- If `domain` configuration option is `true` and domains are not available, an error will result | ||
- More accurate error reporting for `completion` event | ||
- It a state error occurred, but a argument error did not, it is possible this would not be reported to our done listener, this has been resolved | ||
- done listener's error argument will now always be the stored error | ||
- internal `result` storage now is stored without the error/first argument, as that is stored elsewhere | ||
- Task and TaskGroup: | ||
- `started` event has been split into `pending` and `running` events for more accurate semantics | ||
- Less used public APIs have now been marked as `private` or `public` depending on their use cases | ||
- `getNames` method has been replaced by just `names` getter, which has its own `toString()` method that makes use of the `nameSeparator` configuration option, alias provided | ||
- `getConfig()` method now `config` getter, alias provided | ||
- `isCompleted() method now `completed` getter, alias provided | ||
- `hasStarted()` method now `started` getter, alias provided | ||
- TaskGroup: | ||
- `getTotalItems()` method now `totalItems` getter, alias provided | ||
- `getItemTotals()` method now `itemTotals getter, alias provided | ||
- Task: | ||
- If `domain` configuration option is `true` and domains are not available, an error will result | ||
- More accurate error reporting for `completion` event | ||
- It a state error occurred, but a argument error did not, it is possible this would not be reported to our done listener, this has been resolved | ||
- done listener's error argument will now always be the stored error | ||
- internal `result` storage now is stored without the error/first argument, as that is stored elsewhere | ||
- People to thank: | ||
- [Peter Flannery](https://github.com/pflannery) for kickstarting the performance research and making it a priority | ||
- [Peter Flannery](https://github.com/pflannery) for kickstarting the performance research and making it a priority | ||
- Issues closed: | ||
- [An unusually large amount of memory usage - issue #19](https://github.com/bevry/taskgroup/issues/19) | ||
- [Disabled optimisation issue: "bad value context for arguments value - issue #12](https://github.com/bevry/taskgroup/issues/12) | ||
- [An unusually large amount of memory usage - issue #19](https://github.com/bevry/taskgroup/issues/19) | ||
- [Disabled optimisation issue: "bad value context for arguments value - issue #12](https://github.com/bevry/taskgroup/issues/12) | ||
@@ -89,4 +93,4 @@ | ||
- Reintroduced `try...catch` for Node v0.8 and browser environments with a workaround to prevent error suppression | ||
- Thanks to [kksharma1618](https://github.com/kksharma1618) for [issue #17](https://github.com/bevry/taskgroup/issues/17) | ||
- Closes [issue #18](https://github.com/bevry/taskgroup/issues/17) | ||
- Thanks to [kksharma1618](https://github.com/kksharma1618) for [issue #17](https://github.com/bevry/taskgroup/issues/17) | ||
- Closes [issue #18](https://github.com/bevry/taskgroup/issues/17) | ||
- You can now ignore all the warnings from the v4.1.0 changelog as the behaviour is more or less the same as v4.0.5 but with added improvements | ||
@@ -96,16 +100,16 @@ | ||
- This release fixes the errors in completion callbacks being swallowed/lost | ||
- Thanks to [kksharma1618](https://github.com/kksharma1618) for [issue #17](https://github.com/bevry/taskgroup/issues/17) | ||
- Thanks to [kksharma1618](https://github.com/kksharma1618) for [issue #17](https://github.com/bevry/taskgroup/issues/17) | ||
- The following changes have been made | ||
- We no longer use `try...catch` at all, if you want error catching in your task, you must not disable domains (they are enabled by default) - [why?](https://github.com/bevry/taskgroup/issues/17#issuecomment-72383610) | ||
- We now force exit the domain when the task's method calls its completion callback | ||
- Domains now wrap only the firing of the task's method, rather than the preparation too as before | ||
- Removed superflous check to ensure a task has a method before execution | ||
- Ensured the actual check to ensure a task has a method before execution also checks if the method is actually a function (via checking for `.bind`) as the superflous check did | ||
- We no longer use `try...catch` at all, if you want error catching in your task, you must not disable domains (they are enabled by default) - [why?](https://github.com/bevry/taskgroup/issues/17#issuecomment-72383610) | ||
- We now force exit the domain when the task's method calls its completion callback | ||
- Domains now wrap only the firing of the task's method, rather than the preparation too as before | ||
- Removed superflous check to ensure a task has a method before execution | ||
- Ensured the actual check to ensure a task has a method before execution also checks if the method is actually a function (via checking for `.bind`) as the superflous check did | ||
- This **could** introduce the following issues in the following cases: | ||
- You may get errors that were suppressed before now showing themselves, this is good, but it may cause unexpected things to break loudly that were breaking silently before | ||
- If you have domains disabled and an error is thrown, you will get a different flow of logic than before as the error will be caught in your code, not TaskGroup's | ||
- The domain's flow has improved, but this may cause a different flow than you were expecting previously | ||
- You may get errors that were suppressed before now showing themselves, this is good, but it may cause unexpected things to break loudly that were breaking silently before | ||
- If you have domains disabled and an error is thrown, you will get a different flow of logic than before as the error will be caught in your code, not TaskGroup's | ||
- The domain's flow has improved, but this may cause a different flow than you were expecting previously | ||
- This **will** introduce the following issues in the following cases: | ||
- If you are still on Node v0.8, synchronous errors and perhaps asynchronous errors thrown within your task method will no longer be caught by TaskGroup (due to Node 0.8's crippled domain functionality) and instead will need to be caught by your code either via preferably sent to the task method's completion callback rather than thrown, or via your own try...catch. But please upgrade to Node 0.10 or higher. | ||
- If you are running TaskGroup in a web browser, you will need to catch errors manually or utilise a domain shim (browserify has one by default) - [why?](https://github.com/bevry/taskgroup/issues/18) | ||
- If you are still on Node v0.8, synchronous errors and perhaps asynchronous errors thrown within your task method will no longer be caught by TaskGroup (due to Node 0.8's crippled domain functionality) and instead will need to be caught by your code either via preferably sent to the task method's completion callback rather than thrown, or via your own try...catch. But please upgrade to Node 0.10 or higher. | ||
- If you are running TaskGroup in a web browser, you will need to catch errors manually or utilise a domain shim (browserify has one by default) - [why?](https://github.com/bevry/taskgroup/issues/18) | ||
- In other words, this release is the most stable yet, but do run your tests (you should always do this) | ||
@@ -132,24 +136,24 @@ | ||
- Significant rewrite with b/c breaks | ||
- Completion listeners should now be accomplished via `.done(listener)` (listens once) or `.whenDone(listener)` (listener persists) | ||
- These methods are promises in that they will execute the listener if the item is already complete | ||
- They listen for the `done` event | ||
- The execution of tasks and groups have had a great deal of investment to ensure execution is intuitive and consistent across different use cases | ||
- Refer to to `src/lib/test/taskgroup-usage-test.coffee` for the guaranteed expectations across different scenarios | ||
- In earlier versions you could use `tasks.exit()` during execution to clear remaning items, stop execution, and exit, you can no longer do this, instead use the completion callback with an error, or call `tasks.clear()` then the completion callback | ||
- Refer to the [new public api docs](http://learn.bevry.me/taskgroup/api) for the latest usage | ||
- Completion listeners should now be accomplished via `.done(listener)` (listens once) or `.whenDone(listener)` (listener persists) | ||
- These methods are promises in that they will execute the listener if the item is already complete | ||
- They listen for the `done` event | ||
- The execution of tasks and groups have had a great deal of investment to ensure execution is intuitive and consistent across different use cases | ||
- Refer to to `src/lib/test/taskgroup-usage-test.coffee` for the guaranteed expectations across different scenarios | ||
- In earlier versions you could use `tasks.exit()` during execution to clear remaning items, stop execution, and exit, you can no longer do this, instead use the completion callback with an error, or call `tasks.clear()` then the completion callback | ||
- Refer to the [new public api docs](http://learn.bevry.me/taskgroup/api) for the latest usage | ||
- Changes | ||
- `complete` event is now `completed`, but you really should be using the new `done` event or the promise methods | ||
- `run` event is now `started` | ||
- A lot of internal variables and methods have had their functionality changed or removed, if a method or variable is not in the [public api](http://learn.bevry.me/taskgroup/api), do not use it | ||
- There is now a default `error` and `completed` listener that will emit the `done` event if there are listeners for it, if there is no `done` event listeners, and an error has occured, we will throw the error | ||
- Tasks and groups will now only receive a default name when required, this is to prevent set names from being over-written by the default | ||
- Adding of tasks and groups to a group instance will now return the group instance rather than the added tasks to ensure chainability, if you want the created tasks, use `.createTask(...)` and `.createGroup(...)` instead, then add the result manually | ||
- `complete` event is now `completed`, but you really should be using the new `done` event or the promise methods | ||
- `run` event is now `started` | ||
- A lot of internal variables and methods have had their functionality changed or removed, if a method or variable is not in the [public api](http://learn.bevry.me/taskgroup/api), do not use it | ||
- There is now a default `error` and `completed` listener that will emit the `done` event if there are listeners for it, if there is no `done` event listeners, and an error has occured, we will throw the error | ||
- Tasks and groups will now only receive a default name when required, this is to prevent set names from being over-written by the default | ||
- Adding of tasks and groups to a group instance will now return the group instance rather than the added tasks to ensure chainability, if you want the created tasks, use `.createTask(...)` and `.createGroup(...)` instead, then add the result manually | ||
- Introductions | ||
- `passed`, `failed`, `destroyed` events are new | ||
- Task only | ||
- new `timeout` option that accepts a number of milliseconds to wait before throwing an error | ||
- new `onError` option that defaults to `'exit'` but can also accept `'ignore'` which will ignore duplicated exit errors (useful when combined with timeout event) | ||
- TaskGroup only | ||
- new `onError` option that defaults to `'exit'` but can also accept `'ignore'` which will ignore all task errors | ||
- new `setNestedConfig(config)` and `setNestedTaskConfig(config)` options to set configuration for all children | ||
- `passed`, `failed`, `destroyed` events are new | ||
- Task only | ||
- new `timeout` option that accepts a number of milliseconds to wait before throwing an error | ||
- new `onError` option that defaults to `'exit'` but can also accept `'ignore'` which will ignore duplicated exit errors (useful when combined with timeout event) | ||
- TaskGroup only | ||
- new `onError` option that defaults to `'exit'` but can also accept `'ignore'` which will ignore all task errors | ||
- new `setNestedConfig(config)` and `setNestedTaskConfig(config)` options to set configuration for all children | ||
@@ -175,3 +179,3 @@ ## v3.4.0 2014 May 8 | ||
- Properly fixed v3.3.3 issue while maintaining node.js v0.8 and browserify support | ||
- Thanks to [pflannery](https://github.com/pflannery) for [pull request #11](https://github.com/bevry/taskgroup/pull/11) | ||
- Thanks to [pflannery](https://github.com/pflannery) for [pull request #11](https://github.com/bevry/taskgroup/pull/11) | ||
@@ -217,4 +221,4 @@ ## v3.3.5 2013 November 28 | ||
- Wrapped Task execution in a domain to catch uncaught errors within the task execution, as well as added checks to ensure the completion callback does not fire multiple times | ||
- These will be reported via the `error` event that the Task will emit | ||
- If the Task is part of a TaskGroup, the TaskGroup will listen for this, kill the TaskGroup and emit an `error` event on the TaskGroup | ||
- These will be reported via the `error` event that the Task will emit | ||
- If the Task is part of a TaskGroup, the TaskGroup will listen for this, kill the TaskGroup and emit an `error` event on the TaskGroup | ||
- Moved from EventEmitter2 to node's own EventEmitter to ensure domain compatibility | ||
@@ -221,0 +225,0 @@ |
@@ -1,3 +0,3 @@ | ||
// 2016 March 8 | ||
// https://github.com/bevry/editions | ||
'use strict' | ||
module.exports = require('editions').requirePackage(__dirname, require) |
@@ -7,4 +7,4 @@ <!-- LICENSEFILE/ --> | ||
<ul><li>Copyright © 2013+ <a href="https://bevry.me">Bevry Pty Ltd</a></li> | ||
<li>Copyright © 2011-2012 <a href="https://balupton.com">Benjamin Lupton</a></li></ul> | ||
<ul><li>Copyright © 2013+ <a href="http://bevry.me">Bevry Pty Ltd</a></li> | ||
<li>Copyright © 2011-2012 <a href="http://balupton.com">Benjamin Lupton</a></li></ul> | ||
@@ -11,0 +11,0 @@ and licensed under: |
119
package.json
{ | ||
"title": "TaskGroup", | ||
"name": "taskgroup", | ||
"version": "5.0.1", | ||
"version": "5.0.2", | ||
"description": "Group together synchronous and asynchronous tasks and execute them with support for concurrency, naming, and nesting.", | ||
"homepage": "https://github.com/bevry/taskgroup", | ||
"homepage": "ssh://git@github.com/bevry/taskgroup", | ||
"license": "MIT", | ||
"keywords": [ | ||
"flow", | ||
"control", | ||
"async", | ||
"sync", | ||
"tasks", | ||
"batch", | ||
"concurrency" | ||
], | ||
"badges": { | ||
@@ -16,13 +25,14 @@ "list": [ | ||
"---", | ||
"slackin", | ||
"patreon", | ||
"gratipay", | ||
"opencollective", | ||
"flattr", | ||
"paypal", | ||
"bitcoin", | ||
"wishlist" | ||
"wishlist", | ||
"---", | ||
"slackin" | ||
], | ||
"config": { | ||
"patreonUsername": "bevry", | ||
"gratipayUsername": "bevry", | ||
"opencollectiveUsername": "bevry", | ||
"flattrUsername": "balupton", | ||
@@ -35,31 +45,21 @@ "paypalURL": "https://bevry.me/paypal", | ||
}, | ||
"keywords": [ | ||
"flow", | ||
"control", | ||
"async", | ||
"sync", | ||
"tasks", | ||
"batch", | ||
"concurrency" | ||
], | ||
"author": "2013+ Bevry Pty Ltd <us@bevry.me> (https://bevry.me), 2011-2012 Benjamin Lupton <b@lupton.cc> (https://balupton.com)", | ||
"author": "2013+ Bevry Pty Ltd <us@bevry.me> (http://bevry.me), 2011-2012 Benjamin Lupton <b@lupton.cc> (http://balupton.com)", | ||
"maintainers": [ | ||
"Benjamin Lupton <b@lupton.cc> (https://balupton.com)" | ||
"Benjamin Lupton <b@lupton.cc> (http://balupton.com)" | ||
], | ||
"contributors": [ | ||
"Benjamin Lupton <b@lupton.cc> (https://balupton.com)", | ||
"Benjamin Lupton <b@lupton.cc> (http://balupton.com)", | ||
"crito <crito@cryptodrunks.net> (https://github.com/crito)", | ||
"Peter Flannery (https://github.com/pflannery)", | ||
"Sean Fridman <mail@seanfridman.com> (https://github.com/sfrdmn)", | ||
"balupton (https://github.com/balupton)" | ||
"Sean Fridman <mail@seanfridman.com> (http://seanfridman.com)" | ||
], | ||
"bugs": { | ||
"url": "https://github.com/bevry/taskgroup/issues" | ||
"url": "ssh://git@github.com/bevry/taskgroup/issues" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "http://github.com/bevry/taskgroup.git" | ||
"url": "ssh://git@github.com/bevry/taskgroup.git" | ||
}, | ||
"engines": { | ||
"node": ">=0.12" | ||
"node": ">=0.8" | ||
}, | ||
@@ -69,3 +69,3 @@ "editions": [ | ||
"description": "Source + ESNext + Require", | ||
"entry": "source/index.js", | ||
"entry": "index.js", | ||
"directory": "source", | ||
@@ -90,3 +90,3 @@ "syntaxes": [ | ||
"description": "Babel Compiled + ES2015 + Require", | ||
"entry": "es2015/index.js", | ||
"entry": "index.js", | ||
"directory": "es2015", | ||
@@ -102,40 +102,43 @@ "syntaxes": [ | ||
"browser": "es2015/index.js", | ||
"scripts": { | ||
"setup": "npm install", | ||
"clean": "rm -Rf ./docs ./es2015", | ||
"compile": "npm run compile:es2015", | ||
"compile:es2015": "babel ./source --out-dir ./es2015 --presets es2015", | ||
"compile:web": "browserify ./web/index.js -t babelify --outfile ./web/out.js", | ||
"meta": "npm run meta:docs && npm run meta:projectz", | ||
"meta:docs": "documentation build -f html -o ./docs -g -p --shallow ./source/lib/*.js", | ||
"meta:projectz": "projectz compile", | ||
"prepare": "npm run compile && npm run test && npm run meta", | ||
"release": "npm run prepare && npm run release:publish && npm run release:tag && npm run release:push", | ||
"release:publish": "npm publish", | ||
"release:tag": "git tag v$npm_package_version -a", | ||
"release:push": "git push origin master && git push origin --tags", | ||
"pretest": "npm run test:eslint", | ||
"test:eslint": "eslint ./source", | ||
"test": "node --harmony -e \"require('editions').requirePackage(process.cwd(), require, 'test.js')\"" | ||
}, | ||
"dependencies": { | ||
"ambi": "^2.5.0", | ||
"ambi": "^3.0.0", | ||
"eachr": "^3.2.0", | ||
"editions": "^1.1.1", | ||
"extendr": "^3.2.0" | ||
"editions": "^1.3.4", | ||
"extendr": "^3.2.2" | ||
}, | ||
"devDependencies": { | ||
"assert-helpers": "^4.4.0", | ||
"babel-cli": "^6.10.1", | ||
"babel-preset-es2015": "^6.9.0", | ||
"documentation": "^4.0.0-beta5", | ||
"eslint": "^2.12.0", | ||
"eslint-plugin-babel": "^3.2.0", | ||
"joe": "^1.8.0", | ||
"joe-reporter-console": "^1.2.1", | ||
"projectz": "^1.1.6", | ||
"browserify": "^13.0.1", | ||
"babelify": "^7.3.0", | ||
"safeps": "^6.3.0" | ||
"assert-helpers": "^4.5.1", | ||
"babel-cli": "^6.26.0", | ||
"babel-preset-es2015": "^6.24.1", | ||
"babelify": "^8.0.0", | ||
"browserify": "^16.2.2", | ||
"documentation": "^8.0.0", | ||
"eslint": "^5.1.0", | ||
"joe": "^2.0.2", | ||
"joe-reporter-console": "^2.0.1", | ||
"projectz": "^1.4.0", | ||
"safeps": "^7.0.1", | ||
"surge": "^0.20.1" | ||
}, | ||
"scripts": { | ||
"our:setup": "npm run our:setup:npm", | ||
"our:setup:npm": "npm install", | ||
"our:clean": "rm -Rf ./docs ./es2015 ./es5 ./out", | ||
"our:compile": "npm run our:compile:es2015", | ||
"our:compile:es2015": "babel ./source --out-dir ./es2015 --presets es2015", | ||
"our:meta": "npm run our:meta:docs && npm run our:meta:projectz", | ||
"our:meta:docs": "documentation build -f html -o ./docs -g --shallow ./source/**.js", | ||
"our:meta:projectz": "projectz compile", | ||
"our:verify": "npm run our:verify:eslint", | ||
"our:verify:eslint": "eslint --fix ./source", | ||
"our:deploy": "echo no need for this project", | ||
"our:test": "npm run our:verify && npm test", | ||
"our:release": "npm run our:release:prepare && npm run our:release:check-changelog && npm run our:release:check-dirty && npm run our:release:tag && npm run our:release:push", | ||
"our:release:prepare": "npm run our:clean && npm run our:compile && npm run our:test && npm run our:meta", | ||
"our:release:check-changelog": "cat ./HISTORY.md | grep v$npm_package_version || (echo add a changelog entry for v$npm_package_version && exit -1)", | ||
"our:release:check-dirty": "git diff --exit-code", | ||
"our:release:tag": "export MESSAGE=$(cat ./HISTORY.md | sed -n \"/## v$npm_package_version/,/##/p\" | sed 's/## //' | awk 'NR>1{print buf}{buf = $0}') && test \"$MESSAGE\" || (echo 'proper changelog entry not found' && exit -1) && git tag v$npm_package_version -am \"$MESSAGE\"", | ||
"our:release:push": "git push origin master && git push origin --tags", | ||
"test": "node --harmony ./test.js --joe-reporter=console" | ||
} | ||
} |
@@ -16,5 +16,4 @@ <!-- TITLE/ --> | ||
<br class="badge-separator" /> | ||
<span class="badge-slackin"><a href="https://slack.bevry.me" title="Join this project's slack community"><img src="https://slack.bevry.me/badge.svg" alt="Slack community badge" /></a></span> | ||
<span class="badge-patreon"><a href="http://patreon.com/bevry" title="Donate to this project using Patreon"><img src="https://img.shields.io/badge/patreon-donate-yellow.svg" alt="Patreon donate button" /></a></span> | ||
<span class="badge-gratipay"><a href="https://www.gratipay.com/bevry" title="Donate weekly to this project using Gratipay"><img src="https://img.shields.io/badge/gratipay-donate-yellow.svg" alt="Gratipay donate button" /></a></span> | ||
<span class="badge-patreon"><a href="https://patreon.com/bevry" title="Donate to this project using Patreon"><img src="https://img.shields.io/badge/patreon-donate-yellow.svg" alt="Patreon donate button" /></a></span> | ||
<span class="badge-opencollective"><a href="https://opencollective.com/bevry" title="Donate to this project using Open Collective"><img src="https://img.shields.io/badge/open%20collective-donate-yellow.svg" alt="Open Collective donate button" /></a></span> | ||
<span class="badge-flattr"><a href="https://flattr.com/profile/balupton" title="Donate to this project using Flattr"><img src="https://img.shields.io/badge/flattr-donate-yellow.svg" alt="Flattr donate button" /></a></span> | ||
@@ -24,2 +23,4 @@ <span class="badge-paypal"><a href="https://bevry.me/paypal" title="Donate to this project using Paypal"><img src="https://img.shields.io/badge/paypal-donate-yellow.svg" alt="PayPal donate button" /></a></span> | ||
<span class="badge-wishlist"><a href="https://bevry.me/wishlist" title="Buy an item on our wishlist for us"><img src="https://img.shields.io/badge/wishlist-donate-yellow.svg" alt="Wishlist browse button" /></a></span> | ||
<br class="badge-separator" /> | ||
<span class="badge-slackin"><a href="https://slack.bevry.me" title="Join this project's slack community"><img src="https://slack.bevry.me/badge.svg" alt="Slack community badge" /></a></span> | ||
@@ -47,3 +48,3 @@ <!-- /BADGES --> | ||
<li>Module: <code>require('taskgroup')</code></li> | ||
<li>CDN URL: <code>//wzrd.in/bundle/taskgroup@5.0.1</code></li></ul> | ||
<li>CDN URL: <code>//wzrd.in/bundle/taskgroup@5.0.2</code></li></ul> | ||
@@ -101,3 +102,3 @@ <a href="http://enderjs.com" title="Ender is a full featured package manager for your browser"><h3>Ender</h3></a><ul> | ||
<ul><li><a href="https://balupton.com">Benjamin Lupton</a></li></ul> | ||
<ul><li><a href="http://balupton.com">Benjamin Lupton</a> — <a href="https://github.com/bevry/taskgroup/commits?author=balupton" title="View the GitHub contributions of Benjamin Lupton on repository bevry/taskgroup">view contributions</a></li></ul> | ||
@@ -108,4 +109,4 @@ <h3>Sponsors</h3> | ||
<span class="badge-patreon"><a href="http://patreon.com/bevry" title="Donate to this project using Patreon"><img src="https://img.shields.io/badge/patreon-donate-yellow.svg" alt="Patreon donate button" /></a></span> | ||
<span class="badge-gratipay"><a href="https://www.gratipay.com/bevry" title="Donate weekly to this project using Gratipay"><img src="https://img.shields.io/badge/gratipay-donate-yellow.svg" alt="Gratipay donate button" /></a></span> | ||
<span class="badge-patreon"><a href="https://patreon.com/bevry" title="Donate to this project using Patreon"><img src="https://img.shields.io/badge/patreon-donate-yellow.svg" alt="Patreon donate button" /></a></span> | ||
<span class="badge-opencollective"><a href="https://opencollective.com/bevry" title="Donate to this project using Open Collective"><img src="https://img.shields.io/badge/open%20collective-donate-yellow.svg" alt="Open Collective donate button" /></a></span> | ||
<span class="badge-flattr"><a href="https://flattr.com/profile/balupton" title="Donate to this project using Flattr"><img src="https://img.shields.io/badge/flattr-donate-yellow.svg" alt="Flattr donate button" /></a></span> | ||
@@ -120,7 +121,6 @@ <span class="badge-paypal"><a href="https://bevry.me/paypal" title="Donate to this project using Paypal"><img src="https://img.shields.io/badge/paypal-donate-yellow.svg" alt="PayPal donate button" /></a></span> | ||
<ul><li><a href="https://balupton.com">Benjamin Lupton</a></li> | ||
<ul><li><a href="http://balupton.com">Benjamin Lupton</a> — <a href="https://github.com/bevry/taskgroup/commits?author=balupton" title="View the GitHub contributions of Benjamin Lupton on repository bevry/taskgroup">view contributions</a></li> | ||
<li><a href="https://github.com/crito">crito</a> — <a href="https://github.com/bevry/taskgroup/commits?author=crito" title="View the GitHub contributions of crito on repository bevry/taskgroup">view contributions</a></li> | ||
<li><a href="https://github.com/pflannery">Peter Flannery</a> — <a href="https://github.com/bevry/taskgroup/commits?author=pflannery" title="View the GitHub contributions of Peter Flannery on repository bevry/taskgroup">view contributions</a></li> | ||
<li><a href="https://github.com/sfrdmn">Sean Fridman</a> — <a href="https://github.com/bevry/taskgroup/commits?author=sfrdmn" title="View the GitHub contributions of Sean Fridman on repository bevry/taskgroup">view contributions</a></li> | ||
<li><a href="https://github.com/balupton">balupton</a> — <a href="https://github.com/bevry/taskgroup/commits?author=balupton" title="View the GitHub contributions of balupton on repository bevry/taskgroup">view contributions</a></li></ul> | ||
<li><a href="http://seanfridman.com">Sean Fridman</a> — <a href="https://github.com/bevry/taskgroup/commits?author=sfrdmn" title="View the GitHub contributions of Sean Fridman on repository bevry/taskgroup">view contributions</a></li></ul> | ||
@@ -138,4 +138,4 @@ <a href="https://github.com/bevry/taskgroup/blob/master/CONTRIBUTING.md#files">Discover how you can contribute by heading on over to the <code>CONTRIBUTING.md</code> file.</a> | ||
<ul><li>Copyright © 2013+ <a href="https://bevry.me">Bevry Pty Ltd</a></li> | ||
<li>Copyright © 2011-2012 <a href="https://balupton.com">Benjamin Lupton</a></li></ul> | ||
<ul><li>Copyright © 2013+ <a href="http://bevry.me">Bevry Pty Ltd</a></li> | ||
<li>Copyright © 2011-2012 <a href="http://balupton.com">Benjamin Lupton</a></li></ul> | ||
@@ -142,0 +142,0 @@ and licensed under: |
@@ -1,3 +0,5 @@ | ||
const {Task} = require('./lib/task') | ||
const {TaskGroup} = require('./lib/taskgroup') | ||
module.exports = {Task, TaskGroup} | ||
'use strict' | ||
const { Task } = require('./lib/task') | ||
const { TaskGroup } = require('./lib/taskgroup') | ||
module.exports = { Task, TaskGroup } |
@@ -0,1 +1,3 @@ | ||
'use strict' | ||
/** | ||
@@ -42,3 +44,3 @@ Base class containing common functionality for {@link Task} and {@link TaskGroup}. | ||
// Allow extensions of this class to prepare the class instance before anything else fires | ||
if ( this.prepare ) { | ||
if (this.prepare) { | ||
this.prepare() | ||
@@ -48,5 +50,5 @@ } | ||
// Set state and config | ||
if ( this.state == null ) this.state = {} | ||
if ( this.config == null ) this.config = {} | ||
if ( this.config.nameSeparator == null ) this.config.nameSeparator = ' ➞ ' | ||
if (this.state == null) this.state = {} | ||
if (this.config == null) this.config = {} | ||
if (this.config.nameSeparator == null) this.config.nameSeparator = ' ➞ ' | ||
@@ -60,3 +62,3 @@ // Generate our listener method that we will beind to different events | ||
// has done listener, forward to that | ||
if ( this.listeners('done').length !== 0 ) { | ||
if (this.listeners('done').length !== 0) { | ||
this.emit('done', ...args) | ||
@@ -66,4 +68,4 @@ } | ||
// has error, but no done listener and no event listener, throw error | ||
else if ( error && this.listeners(event).length === 1 ) { | ||
if ( event === 'error' ) { | ||
else if (error && this.listeners(event).length === 1) { | ||
if (event === 'error') { | ||
throw error | ||
@@ -132,5 +134,5 @@ } | ||
// Fetch | ||
const names = [], {name, parent, nameSeparator} = this.config | ||
if ( parent ) names.push(...parent.names) | ||
if ( name !== false ) names.push(this.name) | ||
const names = [], { name, parent, nameSeparator } = this.config | ||
if (parent) names.push(...parent.names) | ||
if (name !== false) names.push(this.name) | ||
names.toString = () => names.join(nameSeparator) | ||
@@ -190,2 +192,2 @@ | ||
// Exports | ||
module.exports = {BaseInterface} | ||
module.exports = { BaseInterface } |
/* eslint no-extra-parens:0 func-style:0 */ | ||
'use strict' | ||
// Imports | ||
const {BaseInterface} = require('./interface') | ||
const {queue, domain} = require('./util') | ||
const { BaseInterface } = require('./interface') | ||
const { queue, domain } = require('./util') | ||
const ambi = require('ambi') | ||
@@ -156,3 +158,3 @@ const extendr = require('extendr') | ||
get exited () { | ||
switch ( this.state.status ) { | ||
switch (this.state.status) { | ||
case 'failed': | ||
@@ -174,3 +176,3 @@ case 'passed': | ||
get completed () { | ||
switch ( this.state.status ) { | ||
switch (this.state.status) { | ||
case 'failed': | ||
@@ -208,3 +210,3 @@ case 'passed': | ||
const taskDomain = this.state.taskDomain | ||
if ( taskDomain ) { | ||
if (taskDomain) { | ||
taskDomain.exit() | ||
@@ -285,5 +287,5 @@ taskDomain.removeAllListeners() | ||
args.forEach(function (arg) { | ||
if ( arg == null ) return | ||
if (arg == null) return | ||
const type = typeof arg | ||
switch ( type ) { | ||
switch (type) { | ||
case 'string': | ||
@@ -306,7 +308,7 @@ opts.name = arg | ||
eachr(opts, (value, key) => { | ||
if ( value == null ) return | ||
switch ( key ) { | ||
if (value == null) return | ||
switch (key) { | ||
case 'on': | ||
eachr(value, (value, key) => { | ||
if ( value ) this.on(key, value) | ||
if (value) this.on(key, value) | ||
}) | ||
@@ -317,3 +319,3 @@ break | ||
eachr(value, (value, key) => { | ||
if ( value ) this.once(key, value) | ||
if (value) this.once(key, value) | ||
}) | ||
@@ -365,3 +367,3 @@ break | ||
let error = this.state.error | ||
if ( args[0] && !error ) { | ||
if (args[0] && !error) { | ||
this.state.error = error = args[0] | ||
@@ -371,5 +373,5 @@ } | ||
// Complete for the first (and hopefully only) time | ||
if ( !this.exited ) { | ||
if (!this.exited) { | ||
// Apply the result if we want to and it exists | ||
if ( this.storeResult ) { | ||
if (this.storeResult) { | ||
this.state.result = args.slice(1) | ||
@@ -414,3 +416,3 @@ } | ||
// Complete for the first (and hopefully only) time | ||
if ( !this.exited ) { | ||
if (!this.exited) { | ||
// Set the status and emit depending on success or failure status | ||
@@ -423,3 +425,3 @@ const status = error ? 'failed' : 'passed' | ||
const args = [error] | ||
if ( this.state.result ) args.push(...this.state.result) | ||
if (this.state.result) args.push(...this.state.result) | ||
this.emit('completed', ...args) | ||
@@ -431,3 +433,3 @@ | ||
// Destroy if desired | ||
if ( this.config.destroyOnceDone ) { | ||
if (this.config.destroyOnceDone) { | ||
this.destroy() | ||
@@ -438,3 +440,3 @@ } | ||
// Error as we have already completed before | ||
else if ( this.config.errorOnExcessCompletions ) { | ||
else if (this.config.errorOnExcessCompletions) { | ||
const completedError = new Error(`The task [${this.names}] just completed, but it had already completed earlier, this is unexpected.`) | ||
@@ -482,3 +484,2 @@ this.emit('error', completedError) | ||
let taskDomain = this.state.taskDomain | ||
const useDomains = this.config.domain !== false | ||
const exitMethod = this.itemCompletionCallback.bind(this) | ||
@@ -488,3 +489,3 @@ let method = this.config.method | ||
// Check that we have a method to fire | ||
if ( !method ) { | ||
if (!method) { | ||
const error = new Error(`The task [${this.names}] failed to run as no method was defined for it.`) | ||
@@ -499,5 +500,5 @@ this.emit('error', error) | ||
// Handle domains | ||
if ( domain ) { | ||
if (domain) { | ||
// Prepare the task domain if we want to and if it doesn't already exist | ||
if ( !taskDomain && this.config.domain !== false ) { | ||
if (!taskDomain && this.config.domain !== false) { | ||
this.state.taskDomain = taskDomain = domain.create() | ||
@@ -507,3 +508,3 @@ taskDomain.on('error', exitMethod) | ||
} | ||
else if ( this.config.domain === true ) { | ||
else if (this.config.domain === true) { | ||
const error = new Error(`The task [${this.names}] failed to run as it requested to use domains but domains are not available.`) | ||
@@ -517,3 +518,3 @@ this.emit('error', error) | ||
const completeMethod = (...args) => { | ||
if ( taskDomain ) { | ||
if (taskDomain) { | ||
this.clearDomain() | ||
@@ -535,3 +536,3 @@ taskDomain = null | ||
// Execute with ambi if appropriate | ||
if ( this.config.ambi !== false ) { | ||
if (this.config.ambi !== false) { | ||
ambi(method, ...taskArgs) | ||
@@ -554,3 +555,3 @@ } | ||
// Fire the method within the domain if desired, otherwise execute directly | ||
if ( taskDomain ) { | ||
if (taskDomain) { | ||
taskDomain.run(fireMethod) | ||
@@ -580,3 +581,3 @@ } | ||
// Already started? | ||
if ( this.state.status !== 'created' ) { | ||
if (this.state.status !== 'created') { | ||
const error = new Error(`Invalid run status for the Task [${this.names}], it was [${this.state.status}] instead of [created].`) | ||
@@ -600,2 +601,2 @@ this.emit('error', error) | ||
// Exports | ||
module.exports = {Task} | ||
module.exports = { Task } |
/* eslint no-extra-parens:0 */ | ||
'use strict' | ||
// Imports | ||
const {BaseInterface} = require('./interface') | ||
const {Task} = require('./task') | ||
const {queue, ensureArray} = require('./util') | ||
const { BaseInterface } = require('./interface') | ||
const { Task } = require('./task') | ||
const { queue, ensureArray } = require('./util') | ||
const extendr = require('extendr') | ||
@@ -64,3 +66,3 @@ const eachr = require('eachr') | ||
static isTaskGroup (group) { | ||
return group && group.type === 'taskgroup' || group instanceof this | ||
return (group && group.type === 'taskgroup') || group instanceof this | ||
} | ||
@@ -103,3 +105,3 @@ | ||
get storeResult () { | ||
const {storeResult, destroyOnceDone} = this.config | ||
const { storeResult, destroyOnceDone } = this.config | ||
return storeResult == null ? destroyOnceDone : (storeResult !== false) | ||
@@ -278,3 +280,3 @@ } | ||
get exited () { | ||
switch ( this.state.status ) { | ||
switch (this.state.status) { | ||
case 'passed': | ||
@@ -335,3 +337,3 @@ case 'failed': | ||
const itemsRemaining = this.state.itemsRemaining | ||
while ( itemsRemaining.length !== 0 ) { | ||
while (itemsRemaining.length !== 0) { | ||
itemsRemaining.pop().destroy() | ||
@@ -367,3 +369,3 @@ } | ||
// Prepare | ||
if ( this.prepare ) { | ||
if (this.prepare) { | ||
this.prepare(...args) | ||
@@ -429,3 +431,3 @@ } | ||
// Auto run if we are going the inline style and have no parent | ||
if ( method ) { | ||
if (method) { | ||
// Add the function as our first unamed task with the extra arguments | ||
@@ -435,3 +437,3 @@ this.addMethod(method) | ||
// If we are the topmost group default run to true | ||
if ( !this.config.parent && run == null ) { | ||
if (!this.config.parent && run == null) { | ||
this.state.run = run = true | ||
@@ -442,3 +444,3 @@ } | ||
// Auto run if we are configured to | ||
if ( run ) { | ||
if (run) { | ||
this.run() | ||
@@ -491,5 +493,5 @@ } | ||
args.forEach(function (arg) { | ||
if ( arg == null ) return | ||
if (arg == null) return | ||
const type = typeof arg | ||
switch ( type ) { | ||
switch (type) { | ||
case 'string': | ||
@@ -512,7 +514,7 @@ opts.name = arg | ||
eachr(opts, (value, key) => { | ||
if ( value == null ) return | ||
switch ( key ) { | ||
if (value == null) return | ||
switch (key) { | ||
case 'on': | ||
eachr(value, (value, key) => { | ||
if ( value ) this.on(key, value) | ||
if (value) this.on(key, value) | ||
}) | ||
@@ -523,3 +525,3 @@ break | ||
eachr(value, (value, key) => { | ||
if ( value ) this.once(key, value) | ||
if (value) this.once(key, value) | ||
}) | ||
@@ -622,5 +624,5 @@ break | ||
method.isTaskGroupMethod = true | ||
if ( !opts.name ) opts.name = 'taskgroup method for ' + this.name | ||
if ( !opts.args ) opts.args = [this.addTaskGroup.bind(this), this.addTask.bind(this)] | ||
if ( opts.storeResult == null ) opts.storeResult = false // by default, hide result for methods | ||
if (!opts.name) opts.name = 'taskgroup method for ' + this.name | ||
if (!opts.args) opts.args = [this.addTaskGroup.bind(this), this.addTask.bind(this)] | ||
if (opts.storeResult == null) opts.storeResult = false // by default, hide result for methods | ||
this.addTask(method, opts) | ||
@@ -647,3 +649,3 @@ return this | ||
// Only add the item if it exists | ||
if ( !item ) return null | ||
if (!item) return null | ||
@@ -661,3 +663,3 @@ // Link our item to ourself | ||
// Bubble task events | ||
if ( Task.isTask(item) ) { | ||
if (Task.isTask(item)) { | ||
// Nested configuration | ||
@@ -667,3 +669,3 @@ item.setConfig(itemConfig, nestedTaskConfig, ...args) | ||
// Bubble the nested events if desired | ||
if ( emitNestedEvents ) { | ||
if (emitNestedEvents) { | ||
item.events.forEach(function (event) { | ||
@@ -681,8 +683,8 @@ item.on(event, function (...args) { | ||
// Bubble group events | ||
else if ( TaskGroup.isTaskGroup(item) ) { | ||
else if (TaskGroup.isTaskGroup(item)) { | ||
// Nested configuration | ||
item.setConfig(itemConfig, {nestedTaskConfig, nestedTaskGroupConfig}, nestedTaskGroupConfig, ...args) | ||
item.setConfig(itemConfig, { nestedTaskConfig, nestedTaskGroupConfig }, nestedTaskGroupConfig, ...args) | ||
// Bubble the nested events if desired | ||
if ( emitNestedEvents ) { | ||
if (emitNestedEvents) { | ||
item.events.forEach(function (event) { | ||
@@ -707,3 +709,3 @@ item.on(event, function (...args) { | ||
// Name default | ||
if ( !item.config.name ) { | ||
if (!item.config.name) { | ||
item.config.name = `${item.type} ${this.totalItems + 1} for [${this.name}]` | ||
@@ -714,3 +716,3 @@ } | ||
// if the item is undecided, then inherit from our decision | ||
if ( item.config.storeResult == null ) { | ||
if (item.config.storeResult == null) { | ||
item.config.storeResult = this.config.storeResult | ||
@@ -723,3 +725,3 @@ } | ||
// Bubble the nested events if desired | ||
if ( emitNestedEvents ) { | ||
if (emitNestedEvents) { | ||
item.events.forEach(function (event) { | ||
@@ -779,3 +781,3 @@ item.on(event, function (...args) { | ||
// Support receiving an existing task instance | ||
if ( Task.isTask(args[0]) ) { | ||
if (Task.isTask(args[0])) { | ||
task = args[0] | ||
@@ -837,3 +839,3 @@ task.setConfig(...args.slice(1)) | ||
// Support receiving an existing group instance | ||
if ( TaskGroup.isTaskGroup(args[0]) ) { | ||
if (TaskGroup.isTaskGroup(args[0])) { | ||
group = args[0] | ||
@@ -893,5 +895,6 @@ group.setConfig(...args.slice(1)) | ||
// Fire the next items | ||
while ( true ) { | ||
/* eslint no-constant-condition:0 */ | ||
while (true) { | ||
const item = this.fireNextItem() | ||
if ( item ) { | ||
if (item) { | ||
items.push(item) | ||
@@ -919,7 +922,7 @@ } | ||
// Can we run the next item? | ||
if ( this.shouldFire ) { | ||
if (this.shouldFire) { | ||
// Fire the next item | ||
// Update our status and notify our listeners | ||
if ( this.state.status !== 'running' ) { | ||
if (this.state.status !== 'running') { | ||
this.state.status = 'running' | ||
@@ -955,4 +958,4 @@ this.emit('running') | ||
// Update error if it exists | ||
if ( this.config.abortOnError && args[0] ) { | ||
if ( !this.state.error ) { | ||
if (this.config.abortOnError && args[0]) { | ||
if (!this.state.error) { | ||
this.state.error = args[0] | ||
@@ -963,3 +966,3 @@ } | ||
// Add the result if desired | ||
if ( this.storeResult && item.storeResult ) { | ||
if (this.storeResult && item.storeResult) { | ||
result.push(args) | ||
@@ -973,3 +976,3 @@ } | ||
// As we no longer have any use for this item, as it has completed, destroy the item if desired | ||
if ( this.config.destroyDoneItems ) { | ||
if (this.config.destroyDoneItems) { | ||
item.destroy() | ||
@@ -1001,3 +1004,3 @@ } | ||
const args = [error] | ||
if ( this.state.result ) args.push(this.state.result) | ||
if (this.state.result) args.push(this.state.result) | ||
this.emit('completed', ...args) | ||
@@ -1009,3 +1012,3 @@ | ||
// Destroy if desired | ||
if ( this.config.destroyOnceDone ) { | ||
if (this.config.destroyOnceDone) { | ||
this.destroy() | ||
@@ -1065,5 +1068,5 @@ } | ||
// Have we started are not destroyed? | ||
if ( this.started && this.state.status !== 'destroyed' ) { | ||
if (this.started && this.state.status !== 'destroyed') { | ||
// Check if we are complete, if so, exit | ||
if ( this.completed ) { | ||
if (this.completed) { | ||
// Finish up | ||
@@ -1074,3 +1077,3 @@ this.finish() | ||
// Otherwise continue firing items if we are wanting to pause | ||
else if ( !this.shouldPause ) { | ||
else if (!this.shouldPause) { | ||
this.fireNextItems() | ||
@@ -1092,3 +1095,3 @@ } | ||
// Prevent running on destroy | ||
if ( this.state.status === 'destroyed' ) { | ||
if (this.state.status === 'destroyed') { | ||
const error = new Error(`Invalid run status for the TaskGroup [${this.names}], it was [${this.state.status}].`) | ||
@@ -1104,3 +1107,3 @@ this.emit('error', error) | ||
// Prepare result, if it doesn't exist | ||
if ( this.storeResult && this.state.result == null ) { | ||
if (this.storeResult && this.state.result == null) { | ||
this.state.result = [] | ||
@@ -1118,2 +1121,2 @@ } | ||
// Export | ||
module.exports = {TaskGroup} | ||
module.exports = { TaskGroup } |
/* eslint no-extra-parens:0 */ | ||
'use strict' | ||
// Domains are crippled in the browser and on node 0.8, so don't use domains in those environments | ||
@@ -12,9 +14,9 @@ const domain = (process.browser || process.versions.node.substr(0, 3) === '0.8') ? null : require('domain') | ||
function errorToString (error) { | ||
if ( !error ) { | ||
if (!error) { | ||
return null | ||
} | ||
else if ( error.stack ) { | ||
else if (error.stack) { | ||
return error.stack.toString() | ||
} | ||
else if ( error.message ) { | ||
else if (error.message) { | ||
return error.message.toString() | ||
@@ -29,3 +31,3 @@ } | ||
function ensureArray (arr) { | ||
if ( !Array.isArray(arr) ) arr = [arr] | ||
if (!Array.isArray(arr)) arr = [arr] | ||
return arr | ||
@@ -35,2 +37,2 @@ } | ||
// Exports | ||
module.exports = {domain, queue, errorToString, ensureArray} | ||
module.exports = { domain, queue, errorToString, ensureArray } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
142845
3489
15
1
+ Addedambi@3.2.0(transitive)
- Removedambi@2.5.0(transitive)
Updatedambi@^3.0.0
Updatededitions@^1.3.4
Updatedextendr@^3.2.2