Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

named-promise-task

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

named-promise-task - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

readme.md

87

dist/index.cjs.js
'use strict';
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
var _defineProperty = _interopDefault(require('@babel/runtime/helpers/defineProperty'));
/**

@@ -11,28 +6,74 @@ * A Named Promise Task

*/
class PromiseTask {
constructor(context, namedWorkers) {
_defineProperty(this, "addTask", (() => {
let pending = Promise.resolve();
const run = async (name, ...values) => {
try {
await pending;
} finally {
return this._namedWorkers[name].call(this._context, ...values);
}
}; // update pending promise so that next task could await for it
var _regeneratorRuntime = require("@babel/runtime/regenerator");
var _asyncToGenerator = require("@babel/runtime/helpers/asyncToGenerator");
return (name, ...values) => pending = run(name, ...values);
})());
var _classCallCheck = require("@babel/runtime/helpers/classCallCheck");
this._context = context;
this._namedWorkers = namedWorkers;
this._pending = Promise.resolve();
} // task executor
var _defineProperty = require("@babel/runtime/helpers/defineProperty");
var PromiseTask = function PromiseTask(context, namedWorkers) {
var _this = this;
}
_classCallCheck(this, PromiseTask);
_defineProperty(this, "addTask", function () {
var pending = Promise.resolve();
var run = /*#__PURE__*/function () {
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(name) {
var _this$_namedWorkers$n,
_len,
values,
_key,
_args = arguments;
return _regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_context.prev = 0;
_context.next = 3;
return pending;
case 3:
_context.prev = 3;
for (_len = _args.length, values = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
values[_key - 1] = _args[_key];
}
return _context.abrupt("return", (_this$_namedWorkers$n = _this._namedWorkers[name]).call.apply(_this$_namedWorkers$n, [_this._context].concat(values)));
case 7:
case "end":
return _context.stop();
}
}
}, _callee, null, [[0,, 3, 7]]);
}));
return function run(_x) {
return _ref.apply(this, arguments);
};
}(); // update pending promise so that next task could await for it
return function (name) {
for (var _len2 = arguments.length, values = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
values[_key2 - 1] = arguments[_key2];
}
return pending = run.apply(void 0, [name].concat(values));
};
}());
this._context = context;
this._namedWorkers = namedWorkers;
this._pending = Promise.resolve();
} // task executor
;
module.exports = PromiseTask;
//# sourceMappingURL=index.cjs.js.map

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

import _defineProperty from '@babel/runtime/helpers/defineProperty';
import _regeneratorRuntime from "@babel/runtime/regenerator";
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _defineProperty from "@babel/runtime/helpers/defineProperty";

@@ -7,28 +10,65 @@ /**

*/
class PromiseTask {
constructor(context, namedWorkers) {
_defineProperty(this, "addTask", (() => {
let pending = Promise.resolve();
var PromiseTask = function PromiseTask(context, namedWorkers) {
var _this = this;
const run = async (name, ...values) => {
try {
await pending;
} finally {
return this._namedWorkers[name].call(this._context, ...values);
}
}; // update pending promise so that next task could await for it
_classCallCheck(this, PromiseTask);
_defineProperty(this, "addTask", function () {
var pending = Promise.resolve();
return (name, ...values) => pending = run(name, ...values);
})());
var run = /*#__PURE__*/function () {
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(name) {
var _this$_namedWorkers$n,
_len,
values,
_key,
_args = arguments;
this._context = context;
this._namedWorkers = namedWorkers;
this._pending = Promise.resolve();
} // task executor
return _regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_context.prev = 0;
_context.next = 3;
return pending;
case 3:
_context.prev = 3;
}
for (_len = _args.length, values = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
values[_key - 1] = _args[_key];
}
return _context.abrupt("return", (_this$_namedWorkers$n = _this._namedWorkers[name]).call.apply(_this$_namedWorkers$n, [_this._context].concat(values)));
case 7:
case "end":
return _context.stop();
}
}
}, _callee, null, [[0,, 3, 7]]);
}));
return function run(_x) {
return _ref.apply(this, arguments);
};
}(); // update pending promise so that next task could await for it
return function (name) {
for (var _len2 = arguments.length, values = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
values[_key2 - 1] = arguments[_key2];
}
return pending = run.apply(void 0, [name].concat(values));
};
}());
this._context = context;
this._namedWorkers = namedWorkers;
this._pending = Promise.resolve();
} // task executor
;
export default PromiseTask;
//# sourceMappingURL=index.esm.js.map
{
"name": "named-promise-task",
"version": "1.0.0",
"version": "1.0.1",
"description": "No Queue, Just a simple promise mechanics to help you run serial tasks.",

@@ -24,2 +24,3 @@ "main": "dist/index.cjs.js",

"@babel/register": "^7.10.5",
"@rollup/plugin-babel": "^5.1.0",
"@rollup/plugin-commonjs": "^14.0.0",

@@ -31,5 +32,2 @@ "@rollup/plugin-node-resolve": "^8.4.0",

"rollup": "^2.23.0",
"rollup-plugin-babel": "^4.4.0",
"rollup-plugin-node-builtins": "^2.1.2",
"rollup-plugin-node-globals": "^1.4.0",
"standard": "^14.3.4"

@@ -40,2 +38,2 @@ },

]
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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