Socket
Socket
Sign inDemoInstall

taskgroup

Package Overview
Dependencies
Maintainers
2
Versions
135
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

taskgroup - npm Package Compare versions

Comparing version 7.17.0 to 7.18.0-next.1627431542.bb674fd2a0538526cf0ad759524d10add94ca49b

12

edition-browsers/index.js

@@ -1,12 +0,12 @@

'use strict'
'use strict';
var _require = require('./task.js'),
Task = _require.Task
Task = _require.Task;
var _require2 = require('./taskgroup.js'),
TaskGroup = _require2.TaskGroup
TaskGroup = _require2.TaskGroup;
module.exports = {
Task: Task,
TaskGroup: TaskGroup,
}
Task: Task,
TaskGroup: TaskGroup
};

@@ -1,2 +0,2 @@

'use strict'
'use strict';
/**

@@ -23,231 +23,90 @@ Base class containing common functionality for {@link Task} and {@link TaskGroup}.

function _typeof(obj) {
'@babel/helpers - typeof'
if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') {
_typeof = function _typeof(obj) {
return typeof obj
}
} else {
_typeof = function _typeof(obj) {
return obj &&
typeof Symbol === 'function' &&
obj.constructor === Symbol &&
obj !== Symbol.prototype
? 'symbol'
: typeof obj
}
}
return _typeof(obj)
}
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _construct(Parent, args, Class) {
if (_isNativeReflectConstruct()) {
_construct = Reflect.construct
} else {
_construct = function _construct(Parent, args, Class) {
var a = [null]
a.push.apply(a, args)
var Constructor = Function.bind.apply(Parent, a)
var instance = new Constructor()
if (Class) _setPrototypeOf(instance, Class.prototype)
return instance
}
}
return _construct.apply(null, arguments)
}
function _construct(Parent, args, Class) { if (_isNativeReflectConstruct()) { _construct = Reflect.construct; } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); }
function _toConsumableArray(arr) {
return (
_arrayWithoutHoles(arr) ||
_iterableToArray(arr) ||
_unsupportedIterableToArray(arr) ||
_nonIterableSpread()
)
}
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() {
throw new TypeError(
'Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.'
)
}
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) {
if (!o) return
if (typeof o === 'string') return _arrayLikeToArray(o, minLen)
var n = Object.prototype.toString.call(o).slice(8, -1)
if (n === 'Object' && o.constructor) n = o.constructor.name
if (n === 'Map' || n === 'Set') return Array.from(o)
if (n === 'Arguments' || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))
return _arrayLikeToArray(o, minLen)
}
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _iterableToArray(iter) {
if (typeof Symbol !== 'undefined' && Symbol.iterator in Object(iter))
return Array.from(iter)
}
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
function _arrayWithoutHoles(arr) {
if (Array.isArray(arr)) return _arrayLikeToArray(arr)
}
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
function _arrayLikeToArray(arr, len) {
if (len == null || len > arr.length) len = arr.length
for (var i = 0, arr2 = new Array(len); i < len; i++) {
arr2[i] = arr[i]
}
return arr2
}
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError('Cannot call a class as a function')
}
}
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a 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)
}
}
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); } }
function _createClass(Constructor, protoProps, staticProps) {
if (protoProps) _defineProperties(Constructor.prototype, protoProps)
if (staticProps) _defineProperties(Constructor, staticProps)
return Constructor
}
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
function _inherits(subClass, superClass) {
if (typeof superClass !== 'function' && superClass !== null) {
throw new TypeError('Super expression must either be null or a function')
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: { value: subClass, writable: true, configurable: true },
})
if (superClass) _setPrototypeOf(subClass, superClass)
}
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) {
_setPrototypeOf =
Object.setPrototypeOf ||
function _setPrototypeOf(o, p) {
o.__proto__ = p
return o
}
return _setPrototypeOf(o, p)
}
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _createSuper(Derived) {
var hasNativeReflectConstruct = _isNativeReflectConstruct()
return function _createSuperInternal() {
var Super = _getPrototypeOf(Derived),
result
if (hasNativeReflectConstruct) {
var NewTarget = _getPrototypeOf(this).constructor
result = Reflect.construct(Super, arguments, NewTarget)
} else {
result = Super.apply(this, arguments)
}
return _possibleConstructorReturn(this, result)
}
}
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _possibleConstructorReturn(self, call) {
if (call && (_typeof(call) === 'object' || typeof call === 'function')) {
return call
}
return _assertThisInitialized(self)
}
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
function _assertThisInitialized(self) {
if (self === void 0) {
throw new ReferenceError(
"this hasn't been initialised - super() hasn't been called"
)
}
return self
}
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _isNativeReflectConstruct() {
if (typeof Reflect === 'undefined' || !Reflect.construct) return false
if (Reflect.construct.sham) return false
if (typeof Proxy === 'function') return true
try {
Date.prototype.toString.call(Reflect.construct(Date, [], function () {}))
return true
} catch (e) {
return false
}
}
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
function _getPrototypeOf(o) {
_getPrototypeOf = Object.setPrototypeOf
? Object.getPrototypeOf
: function _getPrototypeOf(o) {
return o.__proto__ || Object.getPrototypeOf(o)
}
return _getPrototypeOf(o)
}
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
var BaseInterface = /*#__PURE__*/ (function (_require$EventEmitter) {
_inherits(BaseInterface, _require$EventEmitter)
var BaseInterface = /*#__PURE__*/function (_require$EventEmitter) {
_inherits(BaseInterface, _require$EventEmitter);
var _super = _createSuper(BaseInterface)
var _super = _createSuper(BaseInterface);
function BaseInterface() {
var _this
function BaseInterface() {
var _this;
_classCallCheck(this, BaseInterface)
_classCallCheck(this, BaseInterface);
_this = _super.call(this) // Allow extensions of this class to prepare the class instance before anything else fires
_this = _super.call(this); // Allow extensions of this class to prepare the class instance before anything else fires
if (_this.prepare) {
_this.prepare()
} // Set state and config
if (_this.prepare) {
_this.prepare();
} // Set state and config
if (_this.state == null) _this.state = {}
if (_this.config == null) _this.config = {}
if (_this.config.nameSeparator == null) _this.config.nameSeparator = ' ➞ ' // Generate our listener method that we will beind to different events
// to add support for the `done` event and better error/event handling
function listener(event) {
for (
var _len = arguments.length,
args = new Array(_len > 1 ? _len - 1 : 0),
_key = 1;
_key < _len;
_key++
) {
args[_key - 1] = arguments[_key]
}
if (_this.state == null) _this.state = {};
if (_this.config == null) _this.config = {};
if (_this.config.nameSeparator == null) _this.config.nameSeparator = ' ➞ '; // Generate our listener method that we will beind to different events
// to add support for the `done` event and better error/event handling
// Prepare
var error = args[0] // has done listener, forward to that
function listener(event) {
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
args[_key - 1] = arguments[_key];
}
if (this.listeners('done').length !== 0) {
this.emit.apply(this, ['done'].concat(args))
} // has error, but no done listener and no event listener, throw error
else if (error && this.listeners(event).length === 1) {
if (event === 'error') {
throw error
} else {
this.emit('error', error)
}
}
} // Listen to the different events without listener
// Prepare
var error = args[0]; // has done listener, forward to that
_this.on('error', listener.bind(_assertThisInitialized(_this), 'error'))
if (this.listeners('done').length !== 0) {
this.emit.apply(this, ['done'].concat(args));
} // has error, but no done listener and no event listener, throw error
else if (error && this.listeners(event).length === 1) {
if (event === 'error') {
throw error;
} else {
this.emit('error', error);
}
}
} // Listen to the different events without listener
_this.on(
'completed',
listener.bind(_assertThisInitialized(_this), 'completed')
) // this.on('halted', listener.bind(this, 'halted'))
// ^ @TODO not yet implemented, would be an alternative to pausing
return _this
}
/**
_this.on('error', listener.bind(_assertThisInitialized(_this), 'error'));
_this.on('completed', listener.bind(_assertThisInitialized(_this), 'completed')); // this.on('halted', listener.bind(this, 'halted'))
// ^ @TODO not yet implemented, would be an alternative to pausing
return _this;
}
/**
Creates and returns new instance of the current class.

@@ -260,9 +119,7 @@ @param {...*} args - The arguments to be forwarded along to the constructor.

_createClass(
BaseInterface,
[
{
key: 'whenDone',
/**
_createClass(BaseInterface, [{
key: "whenDone",
value:
/**
Attaches the listener to the `done` event to be emitted each time.

@@ -274,9 +131,9 @@ @param {Function} listener - Attaches to the `done` event.

*/
value: function whenDone(listener) {
// Attach the listener
this.on('done', listener.bind(this)) // Chain
function whenDone(listener) {
// Attach the listener
this.on('done', listener.bind(this)); // Chain
return this
},
/**
return this;
}
/**
Attaches the listener to the `done` event to be emitted only once, then removed to not fire again.

@@ -288,12 +145,12 @@ @param {Function} listener - Attaches to the `done` event.

*/
},
{
key: 'onceDone',
value: function onceDone(listener) {
// Attach the listener
this.once('done', listener.bind(this)) // Chain
return this
},
/**
}, {
key: "onceDone",
value: function onceDone(listener) {
// Attach the listener
this.once('done', listener.bind(this)); // Chain
return this;
}
/**
Alias for {@link BaseInterface#onceDone}

@@ -305,9 +162,9 @@ @param {Function} listener - Attaches to the `done` event.

*/
},
{
key: 'done',
value: function done(listener) {
return this.onceDone(listener)
},
/**
}, {
key: "done",
value: function done(listener) {
return this.onceDone(listener);
}
/**
Gets our name prepended by all of our parents names

@@ -317,75 +174,23 @@ @type {Array}

*/
},
{
key: 'getNames',
// ---------------------------------
// Backwards compatability helpers
value: function getNames(opts) {
return opts && opts.separator
? this.names.join(opts.separator)
: this.names
},
},
{
key: 'getConfig',
value: function getConfig() {
return this.config
},
},
{
key: 'getTotalItems',
value: function getTotalItems() {
return this.totalItems
},
},
{
key: 'getItemTotals',
value: function getItemTotals() {
return this.itemTotals
},
},
{
key: 'isCompleted',
value: function isCompleted() {
return this.completed
},
},
{
key: 'hasStarted',
value: function hasStarted() {
return this.started
},
},
{
key: 'addGroup',
value: function addGroup() {
return this.addTaskGroup.apply(this, arguments)
},
},
{
key: 'clear',
value: function clear() {
this.clearRemaining.apply(this, arguments)
return this
},
},
{
key: 'names',
get: function get() {
// Fetch
var names = [],
_this$config = this.config,
name = _this$config.name,
parent = _this$config.parent,
nameSeparator = _this$config.nameSeparator
if (parent) names.push.apply(names, _toConsumableArray(parent.names))
if (name !== false) names.push(this.name)
names.toString = function () {
return names.join(nameSeparator)
} // Return
}, {
key: "names",
get: function get() {
// Fetch
var names = [],
_this$config = this.config,
name = _this$config.name,
parent = _this$config.parent,
nameSeparator = _this$config.nameSeparator;
if (parent) names.push.apply(names, _toConsumableArray(parent.names));
if (name !== false) names.push(this.name);
return names
},
/**
names.toString = function () {
return names.join(nameSeparator);
}; // Return
return names;
}
/**
Get the name of our instance.

@@ -396,37 +201,68 @@ If the name was never configured, then return the name in the format of `'${this.type} ${Math.random()}'` to output something like `task 0.2123`

*/
},
{
key: 'name',
get: function get() {
return (
this.config.name ||
this.state.name ||
(this.state.name = ''.concat(this.type, ' ').concat(Math.random()))
)
},
},
],
[
{
key: 'create',
value: function create() {
for (
var _len2 = arguments.length, args = new Array(_len2), _key2 = 0;
_key2 < _len2;
_key2++
) {
args[_key2] = arguments[_key2]
}
return _construct(this, args)
},
},
]
)
}, {
key: "name",
get: function get() {
return this.config.name || this.state.name || (this.state.name = "".concat(this.type, " ").concat(Math.random()));
} // ---------------------------------
// Backwards compatability helpers
return BaseInterface
})(require('events').EventEmitter) // Exports
}, {
key: "getNames",
value: function getNames(opts) {
return opts && opts.separator ? this.names.join(opts.separator) : this.names;
}
}, {
key: "getConfig",
value: function getConfig() {
return this.config;
}
}, {
key: "getTotalItems",
value: function getTotalItems() {
return this.totalItems;
}
}, {
key: "getItemTotals",
value: function getItemTotals() {
return this.itemTotals;
}
}, {
key: "isCompleted",
value: function isCompleted() {
return this.completed;
}
}, {
key: "hasStarted",
value: function hasStarted() {
return this.started;
}
}, {
key: "addGroup",
value: function addGroup() {
return this.addTaskGroup.apply(this, arguments);
}
}, {
key: "clear",
value: function clear() {
this.clearRemaining.apply(this, arguments);
return this;
}
}], [{
key: "create",
value: function create() {
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
args[_key2] = arguments[_key2];
}
return _construct(this, args);
}
}]);
return BaseInterface;
}(require('events').EventEmitter); // Exports
module.exports = {
BaseInterface: BaseInterface,
}
BaseInterface: BaseInterface
};
/* eslint no-extra-parens:0 func-style:0 */
'use strict' // Imports
'use strict'; // Imports
function _toConsumableArray(arr) {
return (
_arrayWithoutHoles(arr) ||
_iterableToArray(arr) ||
_unsupportedIterableToArray(arr) ||
_nonIterableSpread()
)
}
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() {
throw new TypeError(
'Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.'
)
}
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) {
if (!o) return
if (typeof o === 'string') return _arrayLikeToArray(o, minLen)
var n = Object.prototype.toString.call(o).slice(8, -1)
if (n === 'Object' && o.constructor) n = o.constructor.name
if (n === 'Map' || n === 'Set') return Array.from(o)
if (n === 'Arguments' || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))
return _arrayLikeToArray(o, minLen)
}
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _iterableToArray(iter) {
if (typeof Symbol !== 'undefined' && Symbol.iterator in Object(iter))
return Array.from(iter)
}
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
function _arrayWithoutHoles(arr) {
if (Array.isArray(arr)) return _arrayLikeToArray(arr)
}
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
function _arrayLikeToArray(arr, len) {
if (len == null || len > arr.length) len = arr.length
for (var i = 0, arr2 = new Array(len); i < len; i++) {
arr2[i] = arr[i]
}
return arr2
}
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
function _typeof(obj) {
'@babel/helpers - typeof'
if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') {
_typeof = function _typeof(obj) {
return typeof obj
}
} else {
_typeof = function _typeof(obj) {
return obj &&
typeof Symbol === 'function' &&
obj.constructor === Symbol &&
obj !== Symbol.prototype
? 'symbol'
: typeof obj
}
}
return _typeof(obj)
}
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError('Cannot call a class as a function')
}
}
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a 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)
}
}
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); } }
function _createClass(Constructor, protoProps, staticProps) {
if (protoProps) _defineProperties(Constructor.prototype, protoProps)
if (staticProps) _defineProperties(Constructor, staticProps)
return Constructor
}
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
function _inherits(subClass, superClass) {
if (typeof superClass !== 'function' && superClass !== null) {
throw new TypeError('Super expression must either be null or a function')
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: { value: subClass, writable: true, configurable: true },
})
if (superClass) _setPrototypeOf(subClass, superClass)
}
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) {
_setPrototypeOf =
Object.setPrototypeOf ||
function _setPrototypeOf(o, p) {
o.__proto__ = p
return o
}
return _setPrototypeOf(o, p)
}
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _createSuper(Derived) {
var hasNativeReflectConstruct = _isNativeReflectConstruct()
return function _createSuperInternal() {
var Super = _getPrototypeOf(Derived),
result
if (hasNativeReflectConstruct) {
var NewTarget = _getPrototypeOf(this).constructor
result = Reflect.construct(Super, arguments, NewTarget)
} else {
result = Super.apply(this, arguments)
}
return _possibleConstructorReturn(this, result)
}
}
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _possibleConstructorReturn(self, call) {
if (call && (_typeof(call) === 'object' || typeof call === 'function')) {
return call
}
return _assertThisInitialized(self)
}
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
function _assertThisInitialized(self) {
if (self === void 0) {
throw new ReferenceError(
"this hasn't been initialised - super() hasn't been called"
)
}
return self
}
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _isNativeReflectConstruct() {
if (typeof Reflect === 'undefined' || !Reflect.construct) return false
if (Reflect.construct.sham) return false
if (typeof Proxy === 'function') return true
try {
Date.prototype.toString.call(Reflect.construct(Date, [], function () {}))
return true
} catch (e) {
return false
}
}
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
function _getPrototypeOf(o) {
_getPrototypeOf = Object.setPrototypeOf
? Object.getPrototypeOf
: function _getPrototypeOf(o) {
return o.__proto__ || Object.getPrototypeOf(o)
}
return _getPrototypeOf(o)
}
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
var _require = require('./interface.js'),
BaseInterface = _require.BaseInterface
BaseInterface = _require.BaseInterface;
var _require2 = require('./util.js'),
queue = _require2.queue,
domain = _require2.domain
queue = _require2.queue,
domain = _require2.domain;
var ambi = require('ambi')
var ambi = require('ambi');
var extendr = require('extendr')
var extendr = require('extendr');
var eachr = require('eachr')
var eachr = require('eachr');
var unbounded = require('unbounded')
var unbounded = require('unbounded');
/**

@@ -224,43 +103,44 @@ Our Task Class

var Task = /*#__PURE__*/ (function (_BaseInterface) {
_inherits(Task, _BaseInterface)
var _super = _createSuper(Task)
var Task = /*#__PURE__*/function (_BaseInterface) {
_inherits(Task, _BaseInterface);
function Task() {
var _this2
var _super = _createSuper(Task);
var _this
function Task() {
var _this2;
_classCallCheck(this, Task)
var _this;
// Initialise BaseInterface
_this = _super.call(this) // State defaults
_classCallCheck(this, Task);
extendr.defaults(_this.state, {
result: null,
error: null,
status: 'created',
}) // Configuration defaults
// Initialise BaseInterface
_this = _super.call(this); // State defaults
extendr.defaults(_this.config, {
// Standard
storeResult: null,
destroyOnceDone: true,
parent: null,
// Unique to Task
method: null,
errorOnExcessCompletions: true,
ambi: true,
domain: null,
args: null,
}) // Apply user configuration
extendr.defaults(_this.state, {
result: null,
error: null,
status: 'created'
}); // Configuration defaults
;(_this2 = _this).setConfig.apply(_this2, arguments)
extendr.defaults(_this.config, {
// Standard
storeResult: null,
destroyOnceDone: true,
parent: null,
// Unique to Task
method: null,
errorOnExcessCompletions: true,
ambi: true,
domain: null,
args: null
}); // Apply user configuration
return _this
} // ===================================
// Typing Helpers
(_this2 = _this).setConfig.apply(_this2, arguments);
/**
return _this;
} // ===================================
// Typing Helpers
/**
The type of our class.

@@ -275,11 +155,130 @@ Used for the purpose of duck typing

_createClass(
Task,
[
{
key: 'resetResult',
// ---------------------------------
// State Changers
/**
_createClass(Task, [{
key: "type",
get: function get() {
return 'task';
}
/**
A helper method to check if the passed argument is a {Task} via instanceof and duck typing.
@param {Task} item - The possible instance of the {Task} that we want to check
@return {Boolean} Whether or not the item is a {Task} instance.
@static
@access public
*/
}, {
key: "events",
get: // ===================================
// Accessors
/**
An {Array} of the events that we may emit.
@type {Array}
@default ['events', 'error', 'pending', 'running', 'failed', 'passed', 'completed', 'done', 'destroyed']
@access protected
*/
function get() {
return ['events', 'error', 'pending', 'running', 'failed', 'passed', 'completed', 'done', 'destroyed'];
}
/**
Fetches the interpreted value of storeResult
@type {boolean}
@access private
*/
}, {
key: "storeResult",
get: function get() {
return this.config.storeResult !== false;
} // -----------------------------------
// State Accessors
/**
The first {Error} that has occured.
@type {Error}
@access protected
*/
}, {
key: "error",
get: function get() {
return this.state.error;
}
/**
A {String} containing our current status. See our {Task} description for available values.
@type {String}
@access protected
*/
}, {
key: "status",
get: function get() {
return this.state.status;
}
/**
An {Array} representing the returned result or the passed {Arguments} of our method (minus the first error argument).
If no result has occured yet, or we don't care, it is null.
@type {?Array}
@access protected
*/
}, {
key: "result",
get: function get() {
return this.state.result;
} // ---------------------------------
// Status Accessors
/**
Have we started execution yet?
@type {Boolean}
@access private
*/
}, {
key: "started",
get: function get() {
return this.state.status !== 'created';
}
/**
Have we finished execution yet?
@type {Boolean}
@access private
*/
}, {
key: "exited",
get: function get() {
switch (this.state.status) {
case 'failed':
case 'passed':
case 'destroyed':
return true;
default:
return false;
}
}
/**
Have we completed execution yet?
@type {Boolean}
@access private
*/
}, {
key: "completed",
get: function get() {
switch (this.state.status) {
case 'failed':
case 'passed':
return true;
default:
return false;
}
} // ---------------------------------
// State Changers
/**
Reset the result.

@@ -291,7 +290,10 @@ At this point this method is internal, as it's functionality may change in the future, and it's outside use is not yet confirmed. If you need such an ability, let us know via the issue tracker.

*/
value: function resetResult() {
this.state.result = null
return this
},
/**
}, {
key: "resetResult",
value: function resetResult() {
this.state.result = null;
return this;
}
/**
Clear the domain

@@ -302,19 +304,19 @@ @chainable

*/
},
{
key: 'clearDomain',
value: function clearDomain() {
var taskDomain = this.state.taskDomain
if (taskDomain) {
taskDomain.exit()
taskDomain.removeAllListeners()
this.state.taskDomain = null
}
}, {
key: "clearDomain",
value: function clearDomain() {
var taskDomain = this.state.taskDomain;
return this
}, // ===================================
// Initialization
if (taskDomain) {
taskDomain.exit();
taskDomain.removeAllListeners();
this.state.taskDomain = null;
}
/**
return this;
} // ===================================
// Initialization
/**
Set the configuration for our instance.

@@ -339,99 +341,86 @@ @param {Object} [config]

*/
},
{
key: 'setConfig',
value: function setConfig() {
var _this3 = this
var opts = {} // Extract the configuration from the arguments
}, {
key: "setConfig",
value: function setConfig() {
var _this3 = this;
for (
var _len = arguments.length, args = new Array(_len), _key = 0;
_key < _len;
_key++
) {
args[_key] = arguments[_key]
}
var opts = {}; // Extract the configuration from the arguments
args.forEach(function (arg) {
if (arg == null) return
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
var type = _typeof(arg)
args.forEach(function (arg) {
if (arg == null) return;
switch (type) {
case 'string':
opts.name = arg
break
var type = _typeof(arg);
case 'function':
opts.method = arg
break
switch (type) {
case 'string':
opts.name = arg;
break;
case 'object':
extendr.deep(opts, arg)
break
case 'function':
opts.method = arg;
break;
default: {
throw new Error(
'Unknown argument type of ['.concat(
type,
'] given to Task::setConfig()'
)
)
}
}
}) // Apply the configuration directly to our instance
case 'object':
extendr.deep(opts, arg);
break;
eachr(opts, function (value, key) {
if (value == null) return
default:
{
throw new Error("Unknown argument type of [".concat(type, "] given to Task::setConfig()"));
}
}
}); // Apply the configuration directly to our instance
switch (key) {
case 'on':
eachr(value, function (value, key) {
if (value) _this3.on(key, value)
})
break
eachr(opts, function (value, key) {
if (value == null) return;
case 'once':
eachr(value, function (value, key) {
if (value) _this3.once(key, value)
})
break
switch (key) {
case 'on':
eachr(value, function (value, key) {
if (value) _this3.on(key, value);
});
break;
case 'whenDone':
_this3.whenDone(value)
case 'once':
eachr(value, function (value, key) {
if (value) _this3.once(key, value);
});
break;
break
case 'whenDone':
_this3.whenDone(value);
case 'onceDone':
case 'done':
case 'next':
_this3.onceDone(value)
break;
break
case 'onceDone':
case 'done':
case 'next':
_this3.onceDone(value);
case 'onError':
case 'pauseOnError':
case 'includeInResults':
case 'sync':
case 'timeout':
case 'exit':
throw new Error(
'Deprecated configuration property ['.concat(
key,
'] given to Task::setConfig()'
)
)
break;
default:
_this3.config[key] = value
break
}
}) // Chain
case 'onError':
case 'pauseOnError':
case 'includeInResults':
case 'sync':
case 'timeout':
case 'exit':
throw new Error("Deprecated configuration property [".concat(key, "] given to Task::setConfig()"));
return this
}, // ===================================
// Workflow
default:
_this3.config[key] = value;
break;
}
}); // Chain
/**
return this;
} // ===================================
// Workflow
/**
What to do when our task method completes.

@@ -444,33 +433,31 @@ Should only ever execute once, if it executes more than once, then we error.

*/
},
{
key: 'itemCompletionCallback',
value: function itemCompletionCallback() {
// Store the first error
var error = this.state.error
for (
var _len2 = arguments.length, args = new Array(_len2), _key2 = 0;
_key2 < _len2;
_key2++
) {
args[_key2] = arguments[_key2]
}
}, {
key: "itemCompletionCallback",
value: function itemCompletionCallback() {
// Store the first error
var error = this.state.error;
if (args[0] && !error) {
this.state.error = error = args[0]
} // Complete for the first (and hopefully only) time
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
args[_key2] = arguments[_key2];
}
if (!this.exited) {
// Apply the result if we want to and it exists
if (this.storeResult) {
this.state.result = args.slice(1)
}
} // Finish up
if (args[0] && !error) {
this.state.error = error = args[0];
} // Complete for the first (and hopefully only) time
this.finish() // Chain
return this
},
/**
if (!this.exited) {
// Apply the result if we want to and it exists
if (this.storeResult) {
this.state.result = args.slice(1);
}
} // Finish up
this.finish(); // Chain
return this;
}
/**
@NOTE Perhaps at some point, we can add abort/exit functionality, but these things have to be considered:

@@ -489,9 +476,9 @@ What will happen to currently running items?

*/
},
{
key: 'abort',
value: function abort() {
throw new Error('not yet implemented')
},
/**
}, {
key: "abort",
value: function abort() {
throw new Error('not yet implemented');
}
/**
Set our task to the completed state.

@@ -502,45 +489,34 @@ @chainable

*/
},
{
key: 'finish',
value: function finish() {
var error = this.state.error // Complete for the first (and hopefully only) time
if (!this.exited) {
// Set the status and emit depending on success or failure status
var status = error ? 'failed' : 'passed'
this.state.status = status
this.emit(status, error) // Notify our listeners we have completed
}, {
key: "finish",
value: function finish() {
var error = this.state.error; // Complete for the first (and hopefully only) time
var args = [error]
if (this.state.result)
args.push.apply(args, _toConsumableArray(this.state.result))
this.emit.apply(this, ['completed'].concat(args)) // Prevent the error from persisting
if (!this.exited) {
// Set the status and emit depending on success or failure status
var status = error ? 'failed' : 'passed';
this.state.status = status;
this.emit(status, error); // Notify our listeners we have completed
this.state.error = null // Destroy if desired
var args = [error];
if (this.state.result) args.push.apply(args, _toConsumableArray(this.state.result));
this.emit.apply(this, ['completed'].concat(args)); // Prevent the error from persisting
if (this.config.destroyOnceDone) {
this.destroy()
}
} // Error as we have already completed before
else if (this.config.errorOnExcessCompletions) {
var source = (
this.config.method.unbounded ||
this.config.method ||
'no longer present'
).toString()
var completedError = new Error(
'The task ['
.concat(
this.names,
'] just completed, but it had already completed earlier, this is unexpected.\nTask Source: '
)
.concat(source)
)
this.emit('error', completedError)
} // Chain
this.state.error = null; // Destroy if desired
return this
},
/**
if (this.config.destroyOnceDone) {
this.destroy();
}
} // Error as we have already completed before
else if (this.config.errorOnExcessCompletions) {
var source = (this.config.method.unbounded || this.config.method || 'no longer present').toString();
var completedError = new Error("The task [".concat(this.names, "] just completed, but it had already completed earlier, this is unexpected.\nTask Source: ").concat(source));
this.emit('error', completedError);
} // Chain
return this;
}
/**
Destroy ourself and prevent ourself from executing ever again.

@@ -551,19 +527,19 @@ @chainable

*/
},
{
key: 'destroy',
value: function destroy() {
// Update our status and notify our listeners
this.state.status = 'destroyed'
this.emit('destroyed') // Clear the domain
this.clearDomain() // Clear result, in case it keeps references to something
}, {
key: "destroy",
value: function destroy() {
// Update our status and notify our listeners
this.state.status = 'destroyed';
this.emit('destroyed'); // Clear the domain
this.resetResult() // Remove all listeners
this.clearDomain(); // Clear result, in case it keeps references to something
this.removeAllListeners() // Chain
this.resetResult(); // Remove all listeners
return this
},
/**
this.removeAllListeners(); // Chain
return this;
}
/**
Fire the task method with our config arguments and wrapped in a domain.

@@ -574,100 +550,88 @@ @chainable

*/
},
{
key: 'fire',
value: function fire() {
var _this4 = this
// Prepare
var taskArgs = (this.config.args || []).slice()
var taskDomain = this.state.taskDomain
var exitMethod = unbounded.binder.call(
this.itemCompletionCallback,
this
)
var method = this.config.method // Check that we have a method to fire
}, {
key: "fire",
value: function fire() {
var _this4 = this;
if (!method) {
var error = new Error(
'The task ['.concat(
this.names,
'] failed to run as no method was defined for it.'
)
)
this.emit('error', error)
return this
} // Bind method
// Prepare
var taskArgs = (this.config.args || []).slice();
var taskDomain = this.state.taskDomain;
var exitMethod = unbounded.binder.call(this.itemCompletionCallback, this);
var method = this.config.method; // Check that we have a method to fire
method = unbounded.binder.call(method, this) // Handle domains
if (!method) {
var error = new Error("The task [".concat(this.names, "] failed to run as no method was defined for it."));
this.emit('error', error);
return this;
} // Bind method
if (domain) {
// Prepare the task domain if we want to and if it doesn't already exist
if (!taskDomain && this.config.domain !== false) {
this.state.taskDomain = taskDomain = domain.create()
taskDomain.on('error', exitMethod)
}
} else if (this.config.domain === true) {
var _error = new Error(
'The task ['.concat(
this.names,
'] failed to run as it requested to use domains but domains are not available.'
)
)
this.emit('error', _error)
return this
} // Domains, as well as process.nextTick, make it so we can't just use exitMethod directly
// Instead we cover it up like so, to ensure the domain exits, as well to ensure the arguments are passed
method = unbounded.binder.call(method, this); // Handle domains
var completeMethod = function completeMethod() {
for (
var _len3 = arguments.length, args = new Array(_len3), _key3 = 0;
_key3 < _len3;
_key3++
) {
args[_key3] = arguments[_key3]
}
if (domain) {
// Prepare the task domain if we want to and if it doesn't already exist
if (!taskDomain && this.config.domain !== false) {
this.state.taskDomain = taskDomain = domain.create();
taskDomain.on('error', exitMethod);
}
} else if (this.config.domain === true) {
var _error = new Error("The task [".concat(this.names, "] failed to run as it requested to use domains but domains are not available."));
if (taskDomain) {
_this4.clearDomain()
this.emit('error', _error);
return this;
} // Domains, as well as process.nextTick, make it so we can't just use exitMethod directly
// Instead we cover it up like so, to ensure the domain exits, as well to ensure the arguments are passed
taskDomain = null
exitMethod.apply(void 0, args)
} else {
// Use the next tick workaround to escape the try...catch scope
// Which would otherwise catch errors inside our code when it shouldn't therefore suppressing errors
queue(function () {
exitMethod.apply(void 0, args)
})
}
} // Our fire function that will be wrapped in a domain or executed directly
var fireMethod = function fireMethod() {
// Execute with ambi if appropriate
if (_this4.config.ambi !== false) {
ambi.apply(void 0, [method].concat(_toConsumableArray(taskArgs)))
} // Otherwise execute directly if appropriate
else {
method.apply(void 0, _toConsumableArray(taskArgs))
}
} // Add the competion callback to the arguments our method will receive
var completeMethod = function completeMethod() {
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
args[_key3] = arguments[_key3];
}
taskArgs.push(completeMethod) // Notify that we are now running
if (taskDomain) {
_this4.clearDomain();
this.state.status = 'running'
this.emit('running') // Fire the method within the domain if desired, otherwise execute directly
taskDomain = null;
exitMethod.apply(void 0, args);
} else {
// Use the next tick workaround to escape the try...catch scope
// Which would otherwise catch errors inside our code when it shouldn't therefore suppressing errors
queue(function () {
exitMethod.apply(void 0, args);
});
}
}; // Our fire function that will be wrapped in a domain or executed directly
if (taskDomain) {
taskDomain.run(fireMethod)
} else {
try {
fireMethod()
} catch (error) {
exitMethod(error)
}
} // Chain
return this
},
/**
var fireMethod = function fireMethod() {
// Execute with ambi if appropriate
if (_this4.config.ambi !== false) {
ambi.apply(void 0, [method].concat(_toConsumableArray(taskArgs)));
} // Otherwise execute directly if appropriate
else {
method.apply(void 0, _toConsumableArray(taskArgs));
}
}; // Add the competion callback to the arguments our method will receive
taskArgs.push(completeMethod); // Notify that we are now running
this.state.status = 'running';
this.emit('running'); // Fire the method within the domain if desired, otherwise execute directly
if (taskDomain) {
taskDomain.run(fireMethod);
} else {
try {
fireMethod();
} catch (error) {
exitMethod(error);
}
} // Chain
return this;
}
/**
Start the execution of the task.

@@ -679,180 +643,38 @@ Will emit an `error` event if the task has already started before.

*/
},
{
key: 'run',
value: function run() {
var _this5 = this
// Already started?
if (this.state.status !== 'created') {
var error = new Error(
'Invalid run status for the Task ['
.concat(this.names, '], it was [')
.concat(this.state.status, '] instead of [created].')
)
this.emit('error', error)
return this
} // Put it into pending state
}, {
key: "run",
value: function run() {
var _this5 = this;
this.state.status = 'pending'
this.emit('pending') // Queue the actual running so we can give time for the listeners to complete before continuing
// Already started?
if (this.state.status !== 'created') {
var error = new Error("Invalid run status for the Task [".concat(this.names, "], it was [").concat(this.state.status, "] instead of [created]."));
this.emit('error', error);
return this;
} // Put it into pending state
queue(function () {
return _this5.fire()
}) // Chain
return this
},
},
{
key: 'type',
get: function get() {
return 'task'
},
/**
A helper method to check if the passed argument is a {Task} via instanceof and duck typing.
@param {Task} item - The possible instance of the {Task} that we want to check
@return {Boolean} Whether or not the item is a {Task} instance.
@static
@access public
*/
},
{
key: 'events',
// ===================================
// Accessors
this.state.status = 'pending';
this.emit('pending'); // Queue the actual running so we can give time for the listeners to complete before continuing
/**
An {Array} of the events that we may emit.
@type {Array}
@default ['events', 'error', 'pending', 'running', 'failed', 'passed', 'completed', 'done', 'destroyed']
@access protected
*/
get: function get() {
return [
'events',
'error',
'pending',
'running',
'failed',
'passed',
'completed',
'done',
'destroyed',
]
},
/**
Fetches the interpreted value of storeResult
@type {boolean}
@access private
*/
},
{
key: 'storeResult',
get: function get() {
return this.config.storeResult !== false
}, // -----------------------------------
// State Accessors
queue(function () {
return _this5.fire();
}); // Chain
/**
The first {Error} that has occured.
@type {Error}
@access protected
*/
},
{
key: 'error',
get: function get() {
return this.state.error
},
/**
A {String} containing our current status. See our {Task} description for available values.
@type {String}
@access protected
*/
},
{
key: 'status',
get: function get() {
return this.state.status
},
/**
An {Array} representing the returned result or the passed {Arguments} of our method (minus the first error argument).
If no result has occured yet, or we don't care, it is null.
@type {?Array}
@access protected
*/
},
{
key: 'result',
get: function get() {
return this.state.result
}, // ---------------------------------
// Status Accessors
return this;
}
}], [{
key: "isTask",
value: function isTask(item) {
return item && item.type === 'task' || item instanceof this;
}
}]);
/**
Have we started execution yet?
@type {Boolean}
@access private
*/
},
{
key: 'started',
get: function get() {
return this.state.status !== 'created'
},
/**
Have we finished execution yet?
@type {Boolean}
@access private
*/
},
{
key: 'exited',
get: function get() {
switch (this.state.status) {
case 'failed':
case 'passed':
case 'destroyed':
return true
return Task;
}(BaseInterface); // Exports
default:
return false
}
},
/**
Have we completed execution yet?
@type {Boolean}
@access private
*/
},
{
key: 'completed',
get: function get() {
switch (this.state.status) {
case 'failed':
case 'passed':
return true
default:
return false
}
},
},
],
[
{
key: 'isTask',
value: function isTask(item) {
return (item && item.type === 'task') || item instanceof this
},
},
]
)
return Task
})(BaseInterface) // Exports
module.exports = {
Task: Task,
}
Task: Task
};
/* eslint no-extra-parens:0 no-warning-comments:0 */
'use strict' // Imports
'use strict'; // Imports
function _construct(Parent, args, Class) {
if (_isNativeReflectConstruct()) {
_construct = Reflect.construct
} else {
_construct = function _construct(Parent, args, Class) {
var a = [null]
a.push.apply(a, args)
var Constructor = Function.bind.apply(Parent, a)
var instance = new Constructor()
if (Class) _setPrototypeOf(instance, Class.prototype)
return instance
}
}
return _construct.apply(null, arguments)
}
function _construct(Parent, args, Class) { if (_isNativeReflectConstruct()) { _construct = Reflect.construct; } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); }
function _toConsumableArray(arr) {
return (
_arrayWithoutHoles(arr) ||
_iterableToArray(arr) ||
_unsupportedIterableToArray(arr) ||
_nonIterableSpread()
)
}
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() {
throw new TypeError(
'Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.'
)
}
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) {
if (!o) return
if (typeof o === 'string') return _arrayLikeToArray(o, minLen)
var n = Object.prototype.toString.call(o).slice(8, -1)
if (n === 'Object' && o.constructor) n = o.constructor.name
if (n === 'Map' || n === 'Set') return Array.from(o)
if (n === 'Arguments' || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))
return _arrayLikeToArray(o, minLen)
}
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _iterableToArray(iter) {
if (typeof Symbol !== 'undefined' && Symbol.iterator in Object(iter))
return Array.from(iter)
}
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
function _arrayWithoutHoles(arr) {
if (Array.isArray(arr)) return _arrayLikeToArray(arr)
}
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
function _arrayLikeToArray(arr, len) {
if (len == null || len > arr.length) len = arr.length
for (var i = 0, arr2 = new Array(len); i < len; i++) {
arr2[i] = arr[i]
}
return arr2
}
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
function _typeof(obj) {
'@babel/helpers - typeof'
if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') {
_typeof = function _typeof(obj) {
return typeof obj
}
} else {
_typeof = function _typeof(obj) {
return obj &&
typeof Symbol === 'function' &&
obj.constructor === Symbol &&
obj !== Symbol.prototype
? 'symbol'
: typeof obj
}
}
return _typeof(obj)
}
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError('Cannot call a class as a function')
}
}
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a 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)
}
}
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); } }
function _createClass(Constructor, protoProps, staticProps) {
if (protoProps) _defineProperties(Constructor.prototype, protoProps)
if (staticProps) _defineProperties(Constructor, staticProps)
return Constructor
}
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
function _inherits(subClass, superClass) {
if (typeof superClass !== 'function' && superClass !== null) {
throw new TypeError('Super expression must either be null or a function')
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: { value: subClass, writable: true, configurable: true },
})
if (superClass) _setPrototypeOf(subClass, superClass)
}
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) {
_setPrototypeOf =
Object.setPrototypeOf ||
function _setPrototypeOf(o, p) {
o.__proto__ = p
return o
}
return _setPrototypeOf(o, p)
}
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _createSuper(Derived) {
var hasNativeReflectConstruct = _isNativeReflectConstruct()
return function _createSuperInternal() {
var Super = _getPrototypeOf(Derived),
result
if (hasNativeReflectConstruct) {
var NewTarget = _getPrototypeOf(this).constructor
result = Reflect.construct(Super, arguments, NewTarget)
} else {
result = Super.apply(this, arguments)
}
return _possibleConstructorReturn(this, result)
}
}
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _possibleConstructorReturn(self, call) {
if (call && (_typeof(call) === 'object' || typeof call === 'function')) {
return call
}
return _assertThisInitialized(self)
}
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
function _assertThisInitialized(self) {
if (self === void 0) {
throw new ReferenceError(
"this hasn't been initialised - super() hasn't been called"
)
}
return self
}
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _isNativeReflectConstruct() {
if (typeof Reflect === 'undefined' || !Reflect.construct) return false
if (Reflect.construct.sham) return false
if (typeof Proxy === 'function') return true
try {
Date.prototype.toString.call(Reflect.construct(Date, [], function () {}))
return true
} catch (e) {
return false
}
}
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
function _getPrototypeOf(o) {
_getPrototypeOf = Object.setPrototypeOf
? Object.getPrototypeOf
: function _getPrototypeOf(o) {
return o.__proto__ || Object.getPrototypeOf(o)
}
return _getPrototypeOf(o)
}
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
var _require = require('./interface.js'),
BaseInterface = _require.BaseInterface
BaseInterface = _require.BaseInterface;
var _require2 = require('./task.js'),
Task = _require2.Task
Task = _require2.Task;
var _require3 = require('./util.js'),
queue = _require3.queue,
ensureArray = _require3.ensureArray
queue = _require3.queue,
ensureArray = _require3.ensureArray;
var extendr = require('extendr')
var extendr = require('extendr');
var eachr = require('eachr')
var eachr = require('eachr');
var unbounded = require('unbounded')
var unbounded = require('unbounded');
/**

@@ -223,57 +88,60 @@ Our TaskGroup class.

var TaskGroup = /*#__PURE__*/ (function (_BaseInterface) {
_inherits(TaskGroup, _BaseInterface)
var _super = _createSuper(TaskGroup)
var TaskGroup = /*#__PURE__*/function (_BaseInterface) {
_inherits(TaskGroup, _BaseInterface);
function TaskGroup() {
var _this3
var _super = _createSuper(TaskGroup);
var _this
function TaskGroup() {
var _this3;
_classCallCheck(this, TaskGroup)
var _this;
_this = _super.call(this) // Prepare (used for class extensions)
_classCallCheck(this, TaskGroup);
if (_this.prepare) {
var _this2
_this = _super.call(this); // Prepare (used for class extensions)
;(_this2 = _this).prepare.apply(_this2, arguments)
} // State defaults
if (_this.prepare) {
var _this2;
extendr.defaults(_this.state, {
result: null,
error: null,
status: 'created',
itemsRemaining: [],
itemsExecutingCount: 0,
itemsDoneCount: 0,
}) // Configuration defaults
(_this2 = _this).prepare.apply(_this2, arguments);
} // State defaults
extendr.defaults(_this.config, {
// Standard
storeResult: null,
destroyOnceDone: true,
parent: null,
// Unique to TaskGroup
method: null,
abortOnError: true,
destroyDoneItems: true,
nestedTaskConfig: {},
nestedTaskGroupConfig: {},
emitNestedEvents: false,
concurrency: 1,
run: null,
}) // Apply user configuration
;(_this3 = _this).setConfig.apply(_this3, arguments) // Give setConfig enough chance to fire
// Changing this to setImmediate breaks a lot of things
// As tasks inside nested taskgroups will fire in any order
extendr.defaults(_this.state, {
result: null,
error: null,
status: 'created',
itemsRemaining: [],
itemsExecutingCount: 0,
itemsDoneCount: 0
}); // Configuration defaults
queue(unbounded.binder.call(_this.autoRun, _assertThisInitialized(_this)))
return _this
} // ===================================
// Typing Helpers
extendr.defaults(_this.config, {
// Standard
storeResult: null,
destroyOnceDone: true,
parent: null,
// Unique to TaskGroup
method: null,
abortOnError: true,
destroyDoneItems: true,
nestedTaskConfig: {},
nestedTaskGroupConfig: {},
emitNestedEvents: false,
concurrency: 1,
run: null
}); // Apply user configuration
/**
(_this3 = _this).setConfig.apply(_this3, arguments); // Give setConfig enough chance to fire
// Changing this to setImmediate breaks a lot of things
// As tasks inside nested taskgroups will fire in any order
queue(unbounded.binder.call(_this.autoRun, _assertThisInitialized(_this)));
return _this;
} // ===================================
// Typing Helpers
/**
The type of our class.

@@ -287,11 +155,305 @@ Used for the purpose of duck typing which is needed when working with node virtual machines

_createClass(
TaskGroup,
[
{
key: 'resetResult',
// ---------------------------------
// State Changers
/**
_createClass(TaskGroup, [{
key: "type",
get: function get() {
return 'taskgroup';
}
/**
A helper method to check if the passed argument is a {TaskGroup} via instanceof and duck typing.
@param {TaskGroup} group - The possible instance of the {TaskGroup} that we want to check
@return {Boolean} Whether or not the item is a {TaskGroup} instance.
@static
@access public
*/
}, {
key: "Task",
get:
/**
A reference to the {Task} class for use in {@link TaskGroup#createTask} if we want to override it.
@type {Task}
@default Task
@access public
*/
function get() {
return Task;
}
/**
A reference to the {TaskGroup} class for use in {@link TaskGroup#createTaskGroup} if we want to override it.
@type {TaskGroup}
@default TaskGroup
@access public
*/
}, {
key: "TaskGroup",
get: function get() {
return TaskGroup;
} // ===================================
// Accessors
/**
An {Array} of the events that we may emit.
@type {Array}
@access protected
*/
}, {
key: "events",
get: function get() {
return ['error', 'pending', 'running', 'passed', 'failed', 'completed', 'done', 'destroyed'];
}
/**
Fetches the interpreted value of storeResult
@type {boolean}
@access private
*/
}, {
key: "storeResult",
get: function get() {
var _this$config = this.config,
storeResult = _this$config.storeResult,
destroyOnceDone = _this$config.destroyOnceDone;
return storeResult == null ? destroyOnceDone : storeResult !== false;
} // -----------------------------------
// State Accessors
/**
The first {Error} that has occured.
@type {Error}
@access protected
*/
}, {
key: "error",
get: function get() {
return this.state.error;
}
/**
A {String} containing our current status. See our {TaskGroup} description for available values.
@type {String}
@access protected
*/
}, {
key: "status",
get: function get() {
return this.state.status;
}
/**
An {Array} that contains the result property for each completed {Task} and {TaskGroup}.
If no result has occured yet, or we don't care, it is null.
@type {?Array}
@access protected
*/
}, {
key: "result",
get: function get() {
return this.state.result;
} // ---------------------------------
// Status Accessors
/**
Gets the total number of items inside our task group.
@type {Number}
@access public
*/
}, {
key: "totalItems",
get: function get() {
var remaining = this.state.itemsRemaining.length;
var executing = this.state.itemsExecutingCount;
var done = this.state.itemsDoneCount;
var total = executing + remaining + done;
return total;
}
/**
Gets the total number count of each of our item lists.
Returns an {Object} containg the hashes:
- remaining - A {Number} of the names of the remaining items.
- executing - A {Number} of the names of the executing items.
- done - A {Number} of the names of the done items.
- total - A {Number} of the total items we have.
- result - A {Number} of the total results we have.
@type {Object}
@access public
*/
}, {
key: "itemTotals",
get: function get() {
var remaining = this.state.itemsRemaining.length;
var executing = this.state.itemsExecutingCount;
var done = this.state.itemsDoneCount;
var result = this.state.result && this.state.result.length;
var total = executing + remaining + done;
return {
remaining: remaining,
executing: executing,
done: done,
total: total,
result: result
};
}
/**
Whether or not we have any items yet to execute.
@type {Boolean}
@access private
*/
}, {
key: "hasRemaining",
get: function get() {
return this.state.itemsRemaining.length !== 0;
}
/**
Whether or not we have any running items.
@type {Boolean}
@access private
*/
}, {
key: "hasRunning",
get: function get() {
return this.state.itemsExecutingCount !== 0;
}
/**
Whether or not we have any items running or remaining.
@type {Boolean}
@access private
*/
}, {
key: "hasItems",
get: function get() {
return this.hasRunning || this.hasRemaining;
}
/**
Whether or not we have an error.
@type {Boolean}
@access private
*/
}, {
key: "hasError",
get: function get() {
return this.state.error != null;
}
/**
Whether or not we have an error or a result.
@type {Boolean}
@access private
*/
}, {
key: "hasResult",
get: function get() {
return this.hasError || this.state.result.length !== 0;
}
/**
Whether or not we have any available slots to execute more items.
@type {Boolean}
@access private
*/
}, {
key: "hasSlots",
get: function get() {
var concurrency = this.config.concurrency;
return concurrency === 0 || this.state.itemsExecutingCount < concurrency;
}
/**
Whether or not we are capable of firing more items.
This is determined whether or not we are not paused, and we have remaning items, and we have slots able to execute those remaning items.
@type {Boolean}
@access private
*/
}, {
key: "shouldFire",
get: function get() {
return !this.shouldPause && this.hasRemaining && this.hasSlots;
}
/**
Whether or not we have errord and want to pause when we have an error.
@type {Boolean}
@access private
*/
}, {
key: "shouldPause",
get: function get() {
return this.config.abortOnError && this.hasError;
}
/**
Whether or not we execution is currently paused.
@type {Boolean}
@access private
*/
}, {
key: "paused",
get: function get() {
return this.shouldPause && !this.hasRunning;
}
/**
Whether or not we have no running or remaining items left.
@type {Boolean}
@access private
*/
}, {
key: "empty",
get: function get() {
return !this.hasItems;
}
/**
Whether or not we have finished execution.
@type {Boolean}
@access private
*/
}, {
key: "exited",
get: function get() {
switch (this.state.status) {
case 'passed':
case 'failed':
case 'destroyed':
return true;
default:
return false;
}
}
/**
Whether or not we have started execution.
@type {Boolean}
@access private
*/
}, {
key: "started",
get: function get() {
return this.state.status !== 'created';
}
/**
Whether or not we execution has completed.
Completion of executed is determined of whether or not we have started, and whether or not we are currently paused or have no remaining and running items left
@type {Boolean}
@access private
*/
}, {
key: "completed",
get: function get() {
return this.started && (this.paused || this.empty);
} // ---------------------------------
// State Changers
/**
Reset the result.

@@ -303,8 +465,11 @@ At this point this method is internal, as it's functionality may change in the future, and it's outside use is not yet confirmed. If you need such an ability, let us know via the issue tracker.

*/
value: function resetResult() {
this.state.result = null // Chain
return this
},
/**
}, {
key: "resetResult",
value: function resetResult() {
this.state.result = null; // Chain
return this;
}
/**
Remove and destroy the remaining items.

@@ -315,17 +480,18 @@ @chainable

*/
},
{
key: 'clearRemaining',
value: function clearRemaining() {
var dropped = 0
var itemsRemaining = this.state.itemsRemaining
while (itemsRemaining.length !== 0) {
itemsRemaining.pop().destroy()
++dropped
} // Return
}, {
key: "clearRemaining",
value: function clearRemaining() {
var dropped = 0;
var itemsRemaining = this.state.itemsRemaining;
return dropped
},
/**
while (itemsRemaining.length !== 0) {
itemsRemaining.pop().destroy();
++dropped;
} // Return
return dropped;
}
/**
Remove and destroy the running items. Here for verboseness.

@@ -336,15 +502,13 @@ @chainable

*/
},
{
key: 'clearRunning',
value: function clearRunning() {
var error = new Error(
'Clearing running items is not possible. Instead remaining items and wait for running items to complete.'
)
this.emit('error', error)
return this
}, // ===================================
// Initialization
/**
}, {
key: "clearRunning",
value: function clearRunning() {
var error = new Error('Clearing running items is not possible. Instead remaining items and wait for running items to complete.');
this.emit('error', error);
return this;
} // ===================================
// Initialization
/**
Autorun ourself under certain conditions.

@@ -359,26 +523,28 @@ Those conditions being:

*/
},
{
key: 'autoRun',
value: function autoRun() {
// Prepare
var method = this.config.method
var run = this.config.run // Auto run if we are going the inline style and have no parent
if (method) {
// Add the function as our first unamed task with the extra arguments
this.addMethod(method) // If we are the topmost group default run to true
}, {
key: "autoRun",
value: function autoRun() {
// Prepare
var method = this.config.method;
var run = this.config.run; // Auto run if we are going the inline style and have no parent
if (!this.config.parent && run == null) {
this.state.run = run = true
}
} // Auto run if we are configured to
if (method) {
// Add the function as our first unamed task with the extra arguments
this.addMethod(method); // If we are the topmost group default run to true
if (run) {
this.run()
} // Chain
if (!this.config.parent && run == null) {
this.state.run = run = true;
}
} // Auto run if we are configured to
return this
},
/**
if (run) {
this.run();
} // Chain
return this;
}
/**
Set the configuration for our instance.

@@ -411,119 +577,106 @@ Despite accepting an {Object} of configuration, we can also accept an {Array} of configuration.

*/
},
{
key: 'setConfig',
value: function setConfig() {
var _this4 = this
var opts = {} // Extract the configuration from the arguments
}, {
key: "setConfig",
value: function setConfig() {
var _this4 = this;
for (
var _len = arguments.length, args = new Array(_len), _key = 0;
_key < _len;
_key++
) {
args[_key] = arguments[_key]
}
var opts = {}; // Extract the configuration from the arguments
args.forEach(function (arg) {
if (arg == null) return
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
var type = _typeof(arg)
args.forEach(function (arg) {
if (arg == null) return;
switch (type) {
case 'string':
opts.name = arg
break
var type = _typeof(arg);
case 'function':
opts.method = arg
break
switch (type) {
case 'string':
opts.name = arg;
break;
case 'object':
extendr.deep(opts, arg) // @TODO why deep?
case 'function':
opts.method = arg;
break;
break
case 'object':
extendr.deep(opts, arg); // @TODO why deep?
default: {
throw new Error(
'Unknown argument type of ['.concat(
type,
'] given to TaskGroup::setConfig()'
)
)
}
}
}) // Apply the configuration directly to our instance
break;
eachr(opts, function (value, key) {
if (value == null) return
default:
{
throw new Error("Unknown argument type of [".concat(type, "] given to TaskGroup::setConfig()"));
}
}
}); // Apply the configuration directly to our instance
switch (key) {
case 'on':
eachr(value, function (value, key) {
if (value) _this4.on(key, value)
})
break
eachr(opts, function (value, key) {
if (value == null) return;
case 'once':
eachr(value, function (value, key) {
if (value) _this4.once(key, value)
})
break
switch (key) {
case 'on':
eachr(value, function (value, key) {
if (value) _this4.on(key, value);
});
break;
case 'whenDone':
_this4.whenDone(value)
case 'once':
eachr(value, function (value, key) {
if (value) _this4.once(key, value);
});
break;
break
case 'whenDone':
_this4.whenDone(value);
case 'onceDone':
case 'done':
case 'next':
_this4.done(value)
break;
break
case 'onceDone':
case 'done':
case 'next':
_this4.done(value);
case 'task':
case 'tasks':
_this4.addTasks(value)
break;
break
case 'task':
case 'tasks':
_this4.addTasks(value);
case 'group':
case 'groups':
case 'taskgroup':
case 'taskgroups':
_this4.addTaskGroups(value)
break;
break
case 'group':
case 'groups':
case 'taskgroup':
case 'taskgroups':
_this4.addTaskGroups(value);
case 'item':
case 'items':
_this4.addItems(value)
break;
break
case 'item':
case 'items':
_this4.addItems(value);
case 'onError':
case 'pauseOnError':
case 'includeInResults':
case 'sync':
case 'timeout':
case 'exit':
case 'nestedConfig':
throw new Error(
'Deprecated configuration property ['.concat(
key,
'] given to TaskGroup::setConfig()'
)
)
break;
default:
_this4.config[key] = value
break
}
}) // Chain
case 'onError':
case 'pauseOnError':
case 'includeInResults':
case 'sync':
case 'timeout':
case 'exit':
case 'nestedConfig':
throw new Error("Deprecated configuration property [".concat(key, "] given to TaskGroup::setConfig()"));
return this
},
/**
default:
_this4.config[key] = value;
break;
}
}); // Chain
return this;
}
/**
Merge passed configuration into {config.nestedTaskConfig}.

@@ -535,12 +688,12 @@ @param {Object} opts - The configuration to merge.

*/
},
{
key: 'setNestedTaskConfig',
value: function setNestedTaskConfig(opts) {
// Fetch and copy options to the state's nested task configuration
extendr.deep(this.state.nestedTaskConfig, opts) // Chain
return this
},
/**
}, {
key: "setNestedTaskConfig",
value: function setNestedTaskConfig(opts) {
// Fetch and copy options to the state's nested task configuration
extendr.deep(this.state.nestedTaskConfig, opts); // Chain
return this;
}
/**
Merge passed configuration into {config.nestedTaskGroupConfig}.

@@ -552,16 +705,16 @@ @param {Object} opts - The configuration to merge.

*/
},
{
key: 'setNestedTaskGroupConfig',
value: function setNestedTaskGroupConfig(opts) {
// Fetch and copy options to the state's nested configuration
extendr.deep(this.state.nestedTaskGroupConfig, opts) // Chain
return this
}, // ===================================
// Items
// ---------------------------------
// TaskGroup Method
}, {
key: "setNestedTaskGroupConfig",
value: function setNestedTaskGroupConfig(opts) {
// Fetch and copy options to the state's nested configuration
extendr.deep(this.state.nestedTaskGroupConfig, opts); // Chain
/**
return this;
} // ===================================
// Items
// ---------------------------------
// TaskGroup Method
/**
Prepare the method and it's configuration, and add it as a task to be executed.

@@ -574,24 +727,20 @@ @param {Function} method - The function we want to execute as the method of this TaskGroup.

*/
},
{
key: 'addMethod',
value: function addMethod(method) {
var opts =
arguments.length > 1 && arguments[1] !== undefined
? arguments[1]
: {}
method = unbounded.binder.call(method, this) // run the taskgroup method on the group, rather than itself
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
}, {
key: "addMethod",
value: function addMethod(method) {
var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
method = unbounded.binder.call(method, this); // run the taskgroup method on the group, rather than itself
this.addTask(method, opts)
return this
}, // ---------------------------------
// Add Item
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
/**
this.addTask(method, opts);
return this;
} // ---------------------------------
// Add Item
/**
Adds a {Task|TaskGroup} instance and configures it from the arguments.

@@ -604,109 +753,81 @@ @param {Task|TaskGroup} item - The instance to add.

*/
},
{
key: 'addItem',
value: function addItem(item) {
// Prepare
var me = this // Only add the item if it exists
if (!item) return null // Link our item to ourself
}, {
key: "addItem",
value: function addItem(item) {
// Prepare
var me = this; // Only add the item if it exists
var itemConfig = {
parent: this,
} // Extract
if (!item) return null; // Link our item to ourself
var nestedTaskGroupConfig = this.config.nestedTaskGroupConfig
var nestedTaskConfig = this.config.nestedTaskConfig
var emitNestedEvents = this.config.emitNestedEvents
var isTask = Task.isTask(item)
var isTaskGroup = TaskGroup.isTaskGroup(item) // Check
var itemConfig = {
parent: this
}; // Extract
if (!isTask && !isTaskGroup) {
var error = new Error('Unknown item type')
this.emit('error', error)
return this
} // Nested configuration
var nestedTaskGroupConfig = this.config.nestedTaskGroupConfig;
var nestedTaskConfig = this.config.nestedTaskConfig;
var emitNestedEvents = this.config.emitNestedEvents;
var isTask = Task.isTask(item);
var isTaskGroup = TaskGroup.isTaskGroup(item); // Check
for (
var _len2 = arguments.length,
args = new Array(_len2 > 1 ? _len2 - 1 : 0),
_key2 = 1;
_key2 < _len2;
_key2++
) {
args[_key2 - 1] = arguments[_key2]
}
if (!isTask && !isTaskGroup) {
var error = new Error('Unknown item type');
this.emit('error', error);
return this;
} // Nested configuration
if (isTask)
item.setConfig.apply(
item,
[itemConfig, nestedTaskConfig].concat(args)
)
else if (isTaskGroup)
item.setConfig.apply(
item,
[
itemConfig,
{
nestedTaskConfig: nestedTaskConfig,
nestedTaskGroupConfig: nestedTaskGroupConfig,
},
nestedTaskGroupConfig,
].concat(args)
) // Name default
// @todo perhaps this can come after item.add emissions, in case the user wants to set the item name there,
// however that is signficant complexity to test, so for now won't bother
if (!item.config.name) {
item.config.name = ''
.concat(item.type, ' ')
.concat(this.totalItems + 1, ' for [')
.concat(this.name, ']')
} // Store Result Default
// if the item is undecided, then inherit from our decision
// @todo perhaps this can come after item.add emissions, in case the user wants to set the item name there,
// however that is signficant complexity to test, so for now won't bother
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
args[_key2 - 1] = arguments[_key2];
}
if (item.config.storeResult == null) {
item.config.storeResult = this.config.storeResult
} // Add the item
if (isTask) item.setConfig.apply(item, [itemConfig, nestedTaskConfig].concat(args));else if (isTaskGroup) item.setConfig.apply(item, [itemConfig, {
nestedTaskConfig: nestedTaskConfig,
nestedTaskGroupConfig: nestedTaskGroupConfig
}, nestedTaskGroupConfig].concat(args)); // Name default
// @todo perhaps this can come after item.add emissions, in case the user wants to set the item name there,
// however that is signficant complexity to test, so for now won't bother
this.state.itemsRemaining.push(item) // When the item completes, update our state
if (!item.config.name) {
item.config.name = "".concat(item.type, " ").concat(this.totalItems + 1, " for [").concat(this.name, "]");
} // Store Result Default
// if the item is undecided, then inherit from our decision
// @todo perhaps this can come after item.add emissions, in case the user wants to set the item name there,
// however that is signficant complexity to test, so for now won't bother
item.done(this.itemDoneCallbackUpdateState.bind(this, item)) // Bubble the nested events if desired
if (emitNestedEvents) {
item.events.forEach(function (event) {
item.on(event, function () {
for (
var _len3 = arguments.length,
args = new Array(_len3),
_key3 = 0;
_key3 < _len3;
_key3++
) {
args[_key3] = arguments[_key3]
}
if (item.config.storeResult == null) {
item.config.storeResult = this.config.storeResult;
} // Add the item
if (isTask)
me.emit.apply(me, ['task.'.concat(event), item].concat(args))
else if (isTaskGroup)
me.emit.apply(me, ['task.'.concat(event), item].concat(args))
me.emit.apply(me, ['item.'.concat(event), item].concat(args))
})
})
} // Emit
if (isTask) this.emit('task.add', item)
else if (isTaskGroup) this.emit('group.add', item)
this.emit('item.add', item) // When the item completes, after user events have fired, continue with the next state
this.state.itemsRemaining.push(item); // When the item completes, update our state
item.done(this.itemDoneCallbackNextState.bind(this, item)) // We may be running and expecting items, if so, fire
// @TODO determine if this should require a new run
item.done(this.itemDoneCallbackUpdateState.bind(this, item)); // Bubble the nested events if desired
this.fire() // Chain
if (emitNestedEvents) {
item.events.forEach(function (event) {
item.on(event, function () {
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
args[_key3] = arguments[_key3];
}
return this
},
/**
if (isTask) me.emit.apply(me, ["task.".concat(event), item].concat(args));else if (isTaskGroup) me.emit.apply(me, ["task.".concat(event), item].concat(args));
me.emit.apply(me, ["item.".concat(event), item].concat(args));
});
});
} // Emit
if (isTask) this.emit('task.add', item);else if (isTaskGroup) this.emit('group.add', item);
this.emit('item.add', item); // When the item completes, after user events have fired, continue with the next state
item.done(this.itemDoneCallbackNextState.bind(this, item)); // We may be running and expecting items, if so, fire
// @TODO determine if this should require a new run
this.fire(); // Chain
return this;
}
/**
Adds {Task|TaskGroup} instances and configures them from the arguments.

@@ -719,26 +840,20 @@ @param {Array} items - Array of {Task|TaskGroup} instances to add to this task group.

*/
},
{
key: 'addItems',
value: function addItems(items) {
var _this5 = this
for (
var _len4 = arguments.length,
args = new Array(_len4 > 1 ? _len4 - 1 : 0),
_key4 = 1;
_key4 < _len4;
_key4++
) {
args[_key4 - 1] = arguments[_key4]
}
}, {
key: "addItems",
value: function addItems(items) {
var _this5 = this;
ensureArray(items).forEach(function (item) {
return _this5.addItem.apply(_this5, [item].concat(args))
})
return this
}, // ---------------------------------
// Add Task
for (var _len4 = arguments.length, args = new Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) {
args[_key4 - 1] = arguments[_key4];
}
/**
ensureArray(items).forEach(function (item) {
return _this5.addItem.apply(_this5, [item].concat(args));
});
return this;
} // ---------------------------------
// Add Task
/**
Creates a {Task} instance and configures it from the arguments.

@@ -750,34 +865,28 @@ If the first argument is already a {Task} instance, then we configure it with the remaining arguments, instead of creating a new {Task} instance.

*/
},
{
key: 'createTask',
value: function createTask() {
// Prepare
var task // Support receiving an existing task instance
for (
var _len5 = arguments.length, args = new Array(_len5), _key5 = 0;
_key5 < _len5;
_key5++
) {
args[_key5] = arguments[_key5]
}
}, {
key: "createTask",
value: function createTask() {
// Prepare
var task; // Support receiving an existing task instance
if (Task.isTask(args[0])) {
var _task
for (var _len5 = arguments.length, args = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
args[_key5] = arguments[_key5];
}
task = args[0]
if (Task.isTask(args[0])) {
var _task;
;(_task = task).setConfig.apply(
_task,
_toConsumableArray(args.slice(1))
)
} // Support receiving arguments to create a task instance
else {
task = _construct(this.Task, args)
} // Return the new task
task = args[0];
return task
},
/**
(_task = task).setConfig.apply(_task, _toConsumableArray(args.slice(1)));
} // Support receiving arguments to create a task instance
else {
task = _construct(this.Task, args);
} // Return the new task
return task;
}
/**
Adds a {Task} instance and configures it from the arguments.

@@ -790,11 +899,11 @@ If a {Task} instance is not supplied, a {Task} instance is created from the arguments.

*/
},
{
key: 'addTask',
value: function addTask() {
var task = this.createTask.apply(this, arguments)
this.addItem(task)
return this
},
/**
}, {
key: "addTask",
value: function addTask() {
var task = this.createTask.apply(this, arguments);
this.addItem(task);
return this;
}
/**
Adds {Task} instances and configures them from the arguments.

@@ -807,26 +916,20 @@ @param {Array} items - Array of {Task} instances to add to this task group.

*/
},
{
key: 'addTasks',
value: function addTasks(items) {
var _this6 = this
for (
var _len6 = arguments.length,
args = new Array(_len6 > 1 ? _len6 - 1 : 0),
_key6 = 1;
_key6 < _len6;
_key6++
) {
args[_key6 - 1] = arguments[_key6]
}
}, {
key: "addTasks",
value: function addTasks(items) {
var _this6 = this;
ensureArray(items).forEach(function (item) {
return _this6.addTask.apply(_this6, [item].concat(args))
})
return this
}, // ---------------------------------
// Add Group
for (var _len6 = arguments.length, args = new Array(_len6 > 1 ? _len6 - 1 : 0), _key6 = 1; _key6 < _len6; _key6++) {
args[_key6 - 1] = arguments[_key6];
}
/**
ensureArray(items).forEach(function (item) {
return _this6.addTask.apply(_this6, [item].concat(args));
});
return this;
} // ---------------------------------
// Add Group
/**
Creates a {TaskGroup} instance and configures it from the arguments.

@@ -838,34 +941,28 @@ If the first argument is already a {TaskGroup} instance, then we configure it with the remaining arguments, instead of creating a new {TaskGroup} instance.

*/
},
{
key: 'createTaskGroup',
value: function createTaskGroup() {
// Prepare
var group // Support receiving an existing group instance
for (
var _len7 = arguments.length, args = new Array(_len7), _key7 = 0;
_key7 < _len7;
_key7++
) {
args[_key7] = arguments[_key7]
}
}, {
key: "createTaskGroup",
value: function createTaskGroup() {
// Prepare
var group; // Support receiving an existing group instance
if (TaskGroup.isTaskGroup(args[0])) {
var _group
for (var _len7 = arguments.length, args = new Array(_len7), _key7 = 0; _key7 < _len7; _key7++) {
args[_key7] = arguments[_key7];
}
group = args[0]
if (TaskGroup.isTaskGroup(args[0])) {
var _group;
;(_group = group).setConfig.apply(
_group,
_toConsumableArray(args.slice(1))
)
} // Support receiving arguments to create a group instance
else {
group = _construct(this.TaskGroup, args)
} // Return the new group
group = args[0];
return group
},
/**
(_group = group).setConfig.apply(_group, _toConsumableArray(args.slice(1)));
} // Support receiving arguments to create a group instance
else {
group = _construct(this.TaskGroup, args);
} // Return the new group
return group;
}
/**
Adds a {TaskGroup} instance and configures it from the arguments.

@@ -878,11 +975,11 @@ If a {TaskGroup} instance is not supplied, a {TaskGroup} instance is created from the arguments.

*/
},
{
key: 'addTaskGroup',
value: function addTaskGroup() {
var group = this.createTaskGroup.apply(this, arguments)
this.addItem(group)
return this
},
/**
}, {
key: "addTaskGroup",
value: function addTaskGroup() {
var group = this.createTaskGroup.apply(this, arguments);
this.addItem(group);
return this;
}
/**
Adds {TaskGroup} instances and configures them from the arguments.

@@ -895,26 +992,20 @@ @param {Array} items - Array of {TaskGroup} instances to add to this task group.

*/
},
{
key: 'addTaskGroups',
value: function addTaskGroups(items) {
var _this7 = this
for (
var _len8 = arguments.length,
args = new Array(_len8 > 1 ? _len8 - 1 : 0),
_key8 = 1;
_key8 < _len8;
_key8++
) {
args[_key8 - 1] = arguments[_key8]
}
}, {
key: "addTaskGroups",
value: function addTaskGroups(items) {
var _this7 = this;
ensureArray(items).forEach(function (item) {
return _this7.addTaskGroup.apply(_this7, [item].concat(args))
})
return this
}, // ===================================
// Workflow
for (var _len8 = arguments.length, args = new Array(_len8 > 1 ? _len8 - 1 : 0), _key8 = 1; _key8 < _len8; _key8++) {
args[_key8 - 1] = arguments[_key8];
}
/**
ensureArray(items).forEach(function (item) {
return _this7.addTaskGroup.apply(_this7, [item].concat(args));
});
return this;
} // ===================================
// Workflow
/**
Fire the next items.

@@ -924,25 +1015,26 @@ @return {Array|false} Either an {Array} of items that were fired or `false` if no items were fired.

*/
},
{
key: 'fireNextItems',
value: function fireNextItems() {
// Prepare
var items = [] // Fire the next items
/* eslint no-constant-condition:0 */
}, {
key: "fireNextItems",
value: function fireNextItems() {
// Prepare
var items = []; // Fire the next items
while (true) {
var item = this.fireNextItem()
/* eslint no-constant-condition:0 */
if (item) {
items.push(item)
} else {
break
}
} // Return the items or false if no items
while (true) {
var item = this.fireNextItem();
var result = items.length !== 0 ? items : false
return result
},
/**
if (item) {
items.push(item);
} else {
break;
}
} // Return the items or false if no items
var result = items.length !== 0 ? items : false;
return result;
}
/**
Fire the next item.

@@ -952,27 +1044,29 @@ @return {Task|TaskGroup|false} Either the {Task|TaskGroup} item that was fired or `false` if no item was fired.

*/
},
{
key: 'fireNextItem',
value: function fireNextItem() {
// Prepare
var result = false // Can we run the next item?
if (this.shouldFire) {
// Fire the next item
// Update our status and notify our listeners
if (this.state.status !== 'running') {
this.state.status = 'running'
this.emit('running')
} // Get the next item and bump the running count
}, {
key: "fireNextItem",
value: function fireNextItem() {
// Prepare
var result = false; // Can we run the next item?
var item = this.state.itemsRemaining.shift()
++this.state.itemsExecutingCount
item.run() // Return the item
if (this.shouldFire) {
// Fire the next item
// Update our status and notify our listeners
if (this.state.status !== 'running') {
this.state.status = 'running';
this.emit('running');
} // Get the next item and bump the running count
result = item
} // Return
return result
},
/**
var item = this.state.itemsRemaining.shift();
++this.state.itemsExecutingCount;
item.run(); // Return the item
result = item;
} // Return
return result;
}
/**
What to do when an item is done. Run before user events.

@@ -985,35 +1079,31 @@ @chainable

*/
},
{
key: 'itemDoneCallbackUpdateState',
value: function itemDoneCallbackUpdateState(item) {
// Prepare
var result = this.state.result // Update error if it exists
for (
var _len9 = arguments.length,
args = new Array(_len9 > 1 ? _len9 - 1 : 0),
_key9 = 1;
_key9 < _len9;
_key9++
) {
args[_key9 - 1] = arguments[_key9]
}
}, {
key: "itemDoneCallbackUpdateState",
value: function itemDoneCallbackUpdateState(item) {
// Prepare
var result = this.state.result; // Update error if it exists
if (this.config.abortOnError && args[0]) {
if (!this.state.error) {
this.state.error = args[0]
}
} // Add the result if desired
for (var _len9 = arguments.length, args = new Array(_len9 > 1 ? _len9 - 1 : 0), _key9 = 1; _key9 < _len9; _key9++) {
args[_key9 - 1] = arguments[_key9];
}
if (this.storeResult && item.storeResult) {
result.push(args)
} // Mark that one less item is running and one more item done
if (this.config.abortOnError && args[0]) {
if (!this.state.error) {
this.state.error = args[0];
}
} // Add the result if desired
--this.state.itemsExecutingCount
++this.state.itemsDoneCount // Chain
return this
},
/**
if (this.storeResult && item.storeResult) {
result.push(args);
} // Mark that one less item is running and one more item done
--this.state.itemsExecutingCount;
++this.state.itemsDoneCount; // Chain
return this;
}
/**
What to do when an item is done. Run after user events.

@@ -1025,16 +1115,17 @@ @chainable

*/
},
{
key: 'itemDoneCallbackNextState',
value: function itemDoneCallbackNextState(item) {
// As we no longer have any use for this item, as it has completed, destroy the item if desired
if (this.config.destroyDoneItems) {
item.destroy()
} // Fire
this.fire() // Chain
}, {
key: "itemDoneCallbackNextState",
value: function itemDoneCallbackNextState(item) {
// As we no longer have any use for this item, as it has completed, destroy the item if desired
if (this.config.destroyDoneItems) {
item.destroy();
} // Fire
return this
},
/**
this.fire(); // Chain
return this;
}
/**
Set our task to the completed state.

@@ -1046,23 +1137,23 @@ @NOTE This doesn't have to be a separate method, it could just go inside `fire` however, it is nice to have here to keep `fire` simple

*/
},
{
key: 'finish',
value: function finish() {
// Set and emmit the appropriate status for our error or non-error
var error = this.state.error
var status = error ? 'failed' : 'passed'
this.state.status = status
this.emit(status, error) // Notity our listners we have completed
var args = [error]
if (this.state.result) args.push(this.state.result)
this.emit.apply(this, ['completed'].concat(args)) // Prevent the error from persisting
}, {
key: "finish",
value: function finish() {
// Set and emmit the appropriate status for our error or non-error
var error = this.state.error;
var status = error ? 'failed' : 'passed';
this.state.status = status;
this.emit(status, error); // Notity our listners we have completed
this.state.error = null // Destroy if desired
var args = [error];
if (this.state.result) args.push(this.state.result);
this.emit.apply(this, ['completed'].concat(args)); // Prevent the error from persisting
if (this.config.destroyOnceDone) {
this.destroy()
}
},
/**
this.state.error = null; // Destroy if desired
if (this.config.destroyOnceDone) {
this.destroy();
}
}
/**
@NOTE Perhaps at some point, we can add abort/exit functionality, but these things have to be considered:

@@ -1081,9 +1172,9 @@ What will happen to currently running items?

*/
},
{
key: 'abort',
value: function abort() {
throw new Error('not yet implemented')
},
/**
}, {
key: "abort",
value: function abort() {
throw new Error('not yet implemented');
}
/**
Destroy ourself and prevent ourself from executing ever again.

@@ -1094,19 +1185,19 @@ @chainable

*/
},
{
key: 'destroy',
value: function destroy() {
// Update our status and notify our listeners
this.state.status = 'destroyed'
this.emit('destroyed') // Clear remaining items to prevent them from running
this.clearRemaining() // Clear result
}, {
key: "destroy",
value: function destroy() {
// Update our status and notify our listeners
this.state.status = 'destroyed';
this.emit('destroyed'); // Clear remaining items to prevent them from running
this.resetResult() // Remove listeners
this.clearRemaining(); // Clear result
this.removeAllListeners() // Chain
this.resetResult(); // Remove listeners
return this
},
/**
this.removeAllListeners(); // Chain
return this;
}
/**
Internal: Either execute the reamining items we are not paused, or complete execution by exiting.

@@ -1117,21 +1208,22 @@ @chainable

*/
},
{
key: 'fire',
value: function fire() {
// Have we started are not destroyed?
if (this.started && this.state.status !== 'destroyed') {
// Check if we are complete, if so, exit
if (this.completed) {
// Finish up
this.finish()
} // Otherwise continue firing items if we are wanting to pause
else if (!this.shouldPause) {
this.fireNextItems()
}
} // Chain
return this
},
/**
}, {
key: "fire",
value: function fire() {
// Have we started are not destroyed?
if (this.started && this.state.status !== 'destroyed') {
// Check if we are complete, if so, exit
if (this.completed) {
// Finish up
this.finish();
} // Otherwise continue firing items if we are wanting to pause
else if (!this.shouldPause) {
this.fireNextItems();
}
} // Chain
return this;
}
/**
Start/restart/resume the execution of the TaskGroup.

@@ -1142,360 +1234,43 @@ @chainable

*/
},
{
key: 'run',
value: function run() {
var _this8 = this
// Prevent running on destroy
if (this.state.status === 'destroyed') {
var error = new Error(
'Invalid run status for the TaskGroup ['
.concat(this.names, '], it was [')
.concat(this.state.status, '].')
)
this.emit('error', error)
return this
} // Put it into pending state
}, {
key: "run",
value: function run() {
var _this8 = this;
this.state.status = 'pending'
this.emit('pending') // Prepare result, if it doesn't exist
// Prevent running on destroy
if (this.state.status === 'destroyed') {
var error = new Error("Invalid run status for the TaskGroup [".concat(this.names, "], it was [").concat(this.state.status, "]."));
this.emit('error', error);
return this;
} // Put it into pending state
if (this.storeResult && this.state.result == null) {
this.state.result = []
} // Queue the actual running so we can give time for the listeners to complete before continuing
queue(function () {
return _this8.fire()
}) // Chain
this.state.status = 'pending';
this.emit('pending'); // Prepare result, if it doesn't exist
return this
},
},
{
key: 'type',
get: function get() {
return 'taskgroup'
},
/**
A helper method to check if the passed argument is a {TaskGroup} via instanceof and duck typing.
@param {TaskGroup} group - The possible instance of the {TaskGroup} that we want to check
@return {Boolean} Whether or not the item is a {TaskGroup} instance.
@static
@access public
*/
},
{
key: 'Task',
if (this.storeResult && this.state.result == null) {
this.state.result = [];
} // Queue the actual running so we can give time for the listeners to complete before continuing
/**
A reference to the {Task} class for use in {@link TaskGroup#createTask} if we want to override it.
@type {Task}
@default Task
@access public
*/
get: function get() {
return Task
},
/**
A reference to the {TaskGroup} class for use in {@link TaskGroup#createTaskGroup} if we want to override it.
@type {TaskGroup}
@default TaskGroup
@access public
*/
},
{
key: 'TaskGroup',
get: function get() {
return TaskGroup
}, // ===================================
// Accessors
/**
An {Array} of the events that we may emit.
@type {Array}
@access protected
*/
},
{
key: 'events',
get: function get() {
return [
'error',
'pending',
'running',
'passed',
'failed',
'completed',
'done',
'destroyed',
]
},
/**
Fetches the interpreted value of storeResult
@type {boolean}
@access private
*/
},
{
key: 'storeResult',
get: function get() {
var _this$config = this.config,
storeResult = _this$config.storeResult,
destroyOnceDone = _this$config.destroyOnceDone
return storeResult == null ? destroyOnceDone : storeResult !== false
}, // -----------------------------------
// State Accessors
queue(function () {
return _this8.fire();
}); // Chain
/**
The first {Error} that has occured.
@type {Error}
@access protected
*/
},
{
key: 'error',
get: function get() {
return this.state.error
},
/**
A {String} containing our current status. See our {TaskGroup} description for available values.
@type {String}
@access protected
*/
},
{
key: 'status',
get: function get() {
return this.state.status
},
/**
An {Array} that contains the result property for each completed {Task} and {TaskGroup}.
If no result has occured yet, or we don't care, it is null.
@type {?Array}
@access protected
*/
},
{
key: 'result',
get: function get() {
return this.state.result
}, // ---------------------------------
// Status Accessors
return this;
}
}], [{
key: "isTaskGroup",
value: function isTaskGroup(group) {
return group && group.type === 'taskgroup' || group instanceof this;
}
}]);
/**
Gets the total number of items inside our task group.
@type {Number}
@access public
*/
},
{
key: 'totalItems',
get: function get() {
var remaining = this.state.itemsRemaining.length
var executing = this.state.itemsExecutingCount
var done = this.state.itemsDoneCount
var total = executing + remaining + done
return total
},
/**
Gets the total number count of each of our item lists.
Returns an {Object} containg the hashes:
- remaining - A {Number} of the names of the remaining items.
- executing - A {Number} of the names of the executing items.
- done - A {Number} of the names of the done items.
- total - A {Number} of the total items we have.
- result - A {Number} of the total results we have.
@type {Object}
@access public
*/
},
{
key: 'itemTotals',
get: function get() {
var remaining = this.state.itemsRemaining.length
var executing = this.state.itemsExecutingCount
var done = this.state.itemsDoneCount
var result = this.state.result && this.state.result.length
var total = executing + remaining + done
return {
remaining: remaining,
executing: executing,
done: done,
total: total,
result: result,
}
},
/**
Whether or not we have any items yet to execute.
@type {Boolean}
@access private
*/
},
{
key: 'hasRemaining',
get: function get() {
return this.state.itemsRemaining.length !== 0
},
/**
Whether or not we have any running items.
@type {Boolean}
@access private
*/
},
{
key: 'hasRunning',
get: function get() {
return this.state.itemsExecutingCount !== 0
},
/**
Whether or not we have any items running or remaining.
@type {Boolean}
@access private
*/
},
{
key: 'hasItems',
get: function get() {
return this.hasRunning || this.hasRemaining
},
/**
Whether or not we have an error.
@type {Boolean}
@access private
*/
},
{
key: 'hasError',
get: function get() {
return this.state.error != null
},
/**
Whether or not we have an error or a result.
@type {Boolean}
@access private
*/
},
{
key: 'hasResult',
get: function get() {
return this.hasError || this.state.result.length !== 0
},
/**
Whether or not we have any available slots to execute more items.
@type {Boolean}
@access private
*/
},
{
key: 'hasSlots',
get: function get() {
var concurrency = this.config.concurrency
return (
concurrency === 0 || this.state.itemsExecutingCount < concurrency
)
},
/**
Whether or not we are capable of firing more items.
This is determined whether or not we are not paused, and we have remaning items, and we have slots able to execute those remaning items.
@type {Boolean}
@access private
*/
},
{
key: 'shouldFire',
get: function get() {
return !this.shouldPause && this.hasRemaining && this.hasSlots
},
/**
Whether or not we have errord and want to pause when we have an error.
@type {Boolean}
@access private
*/
},
{
key: 'shouldPause',
get: function get() {
return this.config.abortOnError && this.hasError
},
/**
Whether or not we execution is currently paused.
@type {Boolean}
@access private
*/
},
{
key: 'paused',
get: function get() {
return this.shouldPause && !this.hasRunning
},
/**
Whether or not we have no running or remaining items left.
@type {Boolean}
@access private
*/
},
{
key: 'empty',
get: function get() {
return !this.hasItems
},
/**
Whether or not we have finished execution.
@type {Boolean}
@access private
*/
},
{
key: 'exited',
get: function get() {
switch (this.state.status) {
case 'passed':
case 'failed':
case 'destroyed':
return true
return TaskGroup;
}(BaseInterface); // Export
default:
return false
}
},
/**
Whether or not we have started execution.
@type {Boolean}
@access private
*/
},
{
key: 'started',
get: function get() {
return this.state.status !== 'created'
},
/**
Whether or not we execution has completed.
Completion of executed is determined of whether or not we have started, and whether or not we are currently paused or have no remaining and running items left
@type {Boolean}
@access private
*/
},
{
key: 'completed',
get: function get() {
return this.started && (this.paused || this.empty)
},
},
],
[
{
key: 'isTaskGroup',
value: function isTaskGroup(group) {
return (group && group.type === 'taskgroup') || group instanceof this
},
},
]
)
return TaskGroup
})(BaseInterface) // Export
module.exports = {
TaskGroup: TaskGroup,
}
TaskGroup: 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
'use strict'; // 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') // Cross-platform (node 0.10+, node 0.8+, browser) compatible setImmediate
var domain = process.browser || process.versions.node.substr(0, 3) === '0.8' ? null : require('domain'); // Cross-platform (node 0.10+, node 0.8+, browser) compatible setImmediate
var queue =
(global || window).setImmediate ||
(process && process.nextTick) ||
function (fn) {
setTimeout(fn, 0)
} // Convert an error to a string
var queue = (global || window).setImmediate || process && process.nextTick || function (fn) {
setTimeout(fn, 0);
}; // Convert an error to a string
function errorToString(error) {
if (!error) {
return null
} else if (error.stack) {
return error.stack.toString()
} else if (error.message) {
return error.message.toString()
} else {
return error.toString()
}
if (!error) {
return null;
} else if (error.stack) {
return error.stack.toString();
} else if (error.message) {
return error.message.toString();
} else {
return error.toString();
}
} // Ensure that the passed array is actually an array
function ensureArray(arr) {
if (!Array.isArray(arr)) arr = [arr]
return arr
if (!Array.isArray(arr)) arr = [arr];
return arr;
} // Exports
module.exports = {
domain: domain,
queue: queue,
errorToString: errorToString,
ensureArray: ensureArray,
}
domain: domain,
queue: queue,
errorToString: errorToString,
ensureArray: ensureArray
};
# History
## v7.18.0 2021 July 28
- Updated dependencies, [base files](https://github.com/bevry/base), and [editions](https://editions.bevry.me) using [boundation](https://github.com/bevry/boundation)
## v7.17.0 2020 October 29

@@ -4,0 +8,0 @@

@@ -19,3 +19,3 @@ <!-- LICENSEFILE/ -->

The above copyright notice and this permission notice (including the next paragraph) shall be included in all copies or substantial portions of the Software.
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

@@ -22,0 +22,0 @@ 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.

{
"title": "TaskGroup",
"name": "taskgroup",
"version": "7.17.0",
"version": "7.18.0-next.1627431542.bb674fd2a0538526cf0ad759524d10add94ca49b",
"description": "Group together synchronous and asynchronous tasks and execute them with support for concurrency, naming, and nesting.",

@@ -24,3 +24,3 @@ "homepage": "https://github.com/bevry/taskgroup",

"list": [
"travisci",
"githubworkflow",
"npmversion",

@@ -42,2 +42,3 @@ "npmdownloads",

"config": {
"githubWorkflow": "bevry",
"githubSponsorsUsername": "balupton",

@@ -52,3 +53,2 @@ "buymeacoffeeUsername": "balupton",

"wishlistURL": "https://bevry.me/wishlist",
"travisTLD": "com",
"githubUsername": "bevry",

@@ -83,3 +83,3 @@ "githubRepository": "taskgroup",

{
"description": "ESNext source code for Node.js 10 || 12 || 14 || 15 with Require for modules",
"description": "ESNext source code for Node.js 10 || 12 || 14 with Require for modules",
"directory": "source",

@@ -94,3 +94,3 @@ "entry": "index.js",

"engines": {
"node": "10 || 12 || 14 || 15",
"node": "10 || 12 || 14",
"browsers": false

@@ -120,23 +120,23 @@ }

"eachr": "^4.5.0",
"extendr": "^5.16.0",
"unbounded": "^3.12.0"
"extendr": "^5.17.0",
"unbounded": "^3.13.0"
},
"devDependencies": {
"@babel/cli": "^7.12.1",
"@babel/core": "^7.12.3",
"@babel/plugin-proposal-object-rest-spread": "^7.12.1",
"@babel/preset-env": "^7.12.1",
"@bevry/update-contributors": "^1.17.0",
"assert-helpers": "^8.1.0",
"eslint": "^7.12.1",
"@babel/cli": "^7.14.8",
"@babel/core": "^7.14.8",
"@babel/plugin-proposal-object-rest-spread": "^7.14.7",
"@babel/preset-env": "^7.14.8",
"@bevry/update-contributors": "^1.18.0",
"assert-helpers": "^8.2.0",
"eslint": "^7.31.0",
"eslint-config-bevry": "^3.23.0",
"eslint-config-prettier": "^6.15.0",
"eslint-plugin-prettier": "^3.1.4",
"jsdoc": "^3.6.6",
"kava": "^5.13.0",
"prettier": "^2.1.2",
"projectz": "^2.17.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^3.4.0",
"jsdoc": "^3.6.7",
"kava": "^5.14.0",
"prettier": "^2.3.2",
"projectz": "^2.18.0",
"safeps": "^10.15.0",
"surge": "^0.21.6",
"valid-directory": "^3.4.0"
"surge": "^0.23.0",
"valid-directory": "^3.7.0"
},

@@ -157,3 +157,3 @@ "scripts": {

"our:release:prepare": "npm run our:clean && npm run our:compile && npm run our:test && npm run our:meta",
"our:release:push": "git push origin master && git push origin --tags",
"our:release:push": "git push origin && git push origin --tags",
"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\"",

@@ -160,0 +160,0 @@ "our:setup": "npm run our:setup:install",

@@ -10,3 +10,3 @@ <!-- TITLE/ -->

<span class="badge-travisci"><a href="http://travis-ci.com/bevry/taskgroup" title="Check this project's build status on TravisCI"><img src="https://img.shields.io/travis/com/bevry/taskgroup/master.svg" alt="Travis CI Build Status" /></a></span>
<span class="badge-githubworkflow"><a href="https://github.com/bevry/taskgroup/actions?query=workflow%3Abevry" title="View the status of this project's GitHub Workflow: bevry"><img src="https://github.com/bevry/taskgroup/workflows/bevry/badge.svg" alt="Status of the GitHub Workflow: bevry" /></a></span>
<span class="badge-npmversion"><a href="https://npmjs.org/package/taskgroup" title="View this project on NPM"><img src="https://img.shields.io/npm/v/taskgroup.svg" alt="NPM version" /></a></span>

@@ -60,3 +60,3 @@ <span class="badge-npmdownloads"><a href="https://npmjs.org/package/taskgroup" title="View this project on NPM"><img src="https://img.shields.io/npm/dm/taskgroup.svg" alt="NPM downloads" /></a></span>

<script type="module">
import * as pkg from '//dev.jspm.io/taskgroup@7.17.0'
import * as pkg from '//dev.jspm.io/taskgroup@7.18.0'
</script>

@@ -70,3 +70,3 @@ ```

<ul><li><code>taskgroup</code> aliases <code>taskgroup/source/index.js</code></li>
<li><code>taskgroup/source/index.js</code> is <a href="https://en.wikipedia.org/wiki/ECMAScript#ES.Next" title="ECMAScript Next">ESNext</a> source code for <a href="https://nodejs.org" title="Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine">Node.js</a> 10 || 12 || 14 || 15 with <a href="https://nodejs.org/dist/latest-v5.x/docs/api/modules.html" title="Node/CJS Modules">Require</a> for modules</li>
<li><code>taskgroup/source/index.js</code> is <a href="https://en.wikipedia.org/wiki/ECMAScript#ES.Next" title="ECMAScript Next">ESNext</a> source code for <a href="https://nodejs.org" title="Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine">Node.js</a> 10 || 12 || 14 with <a href="https://nodejs.org/dist/latest-v5.x/docs/api/modules.html" title="Node/CJS Modules">Require</a> for modules</li>
<li><code>taskgroup/edition-browsers/index.js</code> is <a href="https://en.wikipedia.org/wiki/ECMAScript#ES.Next" title="ECMAScript Next">ESNext</a> compiled for web browsers with <a href="https://nodejs.org/dist/latest-v5.x/docs/api/modules.html" title="Node/CJS Modules">Require</a> for modules</li></ul>

@@ -73,0 +73,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc