New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

task-handler

Package Overview
Dependencies
Maintainers
1
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

task-handler - npm Package Compare versions

Comparing version 2.1.0 to 2.2.0

2

dist/index.js

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

"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=createTaskHandler,require("core-js/modules/es6.regexp.to-string"),require("core-js/modules/es6.array.from"),require("core-js/modules/web.dom.iterable"),require("core-js/modules/es6.array.iterator"),require("core-js/modules/es6.string.iterator"),require("core-js/modules/es6.map"),require("core-js/modules/es6.object.freeze"),require("regenerator-runtime/runtime"),require("core-js/modules/es7.symbol.async-iterator"),require("core-js/modules/es6.symbol"),require("core-js/modules/es6.promise");var _constants=require("./constants"),_defer=_interopRequireDefault(require("./defer"));function _interopRequireDefault(a){return a&&a.__esModule?a:{default:a}}function _toConsumableArray(a){return _arrayWithoutHoles(a)||_iterableToArray(a)||_nonIterableSpread()}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance")}function _iterableToArray(a){if(Symbol.iterator in Object(a)||"[object Arguments]"===Object.prototype.toString.call(a))return Array.from(a)}function _arrayWithoutHoles(a){if(Array.isArray(a)){for(var b=0,c=Array(a.length);b<a.length;b++)c[b]=a[b];return c}}function _slicedToArray(a,b){return _arrayWithHoles(a)||_iterableToArrayLimit(a,b)||_nonIterableRest()}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}function _iterableToArrayLimit(a,b){var c=[],d=!0,e=!1,f=void 0;try{for(var g,h=a[Symbol.iterator]();!(d=(g=h.next()).done)&&(c.push(g.value),!(b&&c.length===b));d=!0);}catch(a){e=!0,f=a}finally{try{d||null==h["return"]||h["return"]()}finally{if(e)throw f}}return c}function _arrayWithHoles(a){if(Array.isArray(a))return a}function _defineProperty(a,b,c){return b in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _typeof(a){return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},_typeof(a)}function asyncGeneratorStep(a,b,c,d,e,f,g){try{var h=a[f](g),i=h.value}catch(a){return void c(a)}h.done?b(i):Promise.resolve(i).then(d,e)}function _asyncToGenerator(a){return function(){var b=this,c=arguments;return new Promise(function(d,e){function f(a){asyncGeneratorStep(h,d,e,f,g,"next",a)}function g(a){asyncGeneratorStep(h,d,e,f,g,"throw",a)}var h=a.apply(b,c);f(void 0)})}}function _awaitAsyncGenerator(a){return new _AwaitValue(a)}function _wrapAsyncGenerator(a){return function(){return new _AsyncGenerator(a.apply(this,arguments))}}function _AsyncGenerator(a){function b(d,e){try{var f=a[d](e),g=f.value,h=g instanceof _AwaitValue;Promise.resolve(h?g.wrapped:g).then(function(a){return h?void b("next",a):void c(f.done?"return":"normal",a)},function(a){b("throw",a)})}catch(a){c("throw",a)}}function c(a,c){switch(a){case"return":d.resolve({value:c,done:!0});break;case"throw":d.reject(c);break;default:d.resolve({value:c,done:!1});}d=d.next,d?b(d.key,d.arg):e=null}var d,e;this._invoke=function(a,c){return new Promise(function(f,g){var h={key:a,arg:c,resolve:f,reject:g,next:null};e?e=e.next=h:(d=e=h,b(a,c))})},"function"!=typeof a.return&&(this.return=void 0)}"function"==typeof Symbol&&Symbol.asyncIterator&&(_AsyncGenerator.prototype[Symbol.asyncIterator]=function(){return this}),_AsyncGenerator.prototype.next=function(a){return this._invoke("next",a)},_AsyncGenerator.prototype.throw=function(a){return this._invoke("throw",a)},_AsyncGenerator.prototype.return=function(a){return this._invoke("return",a)};function _AwaitValue(a){this.wrapped=a}function createTaskRef(a,b,c,d){var e;c.cancel(b);var f,g,h,i,j=function(){return f?f:(f=new Promise(function(a,b){g=[a,b]}),f)},k=(e={get result(){return k.status.complete?h:void 0},get promise(){if("every"===a)throw new Error("[ERROR] | task-handler | \"ref.promise()\" may only be used with non-iterative tasks such as after, defer, and job, but tried with \"".concat(a,"\" task with ID: \"").concat(b,"\""));return function(){var a=_asyncToGenerator(regeneratorRuntime.mark(function a(){return regeneratorRuntime.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:if(!f){a.next=2;break}return a.abrupt("return",f);case 2:if(a.prev=2,!k.status.complete){a.next=5;break}return a.abrupt("return",k);case 5:return j(),a.next=8,f;case 8:return a.abrupt("return",k);case 11:throw a.prev=11,a.t0=a["catch"](2),k.status.error=!0,h=a.t0,a.t0;case 16:return a.prev=16,g=void 0,f=void 0,a.finish(16);case 20:case"end":return a.stop();}},a,this,[[2,11,16,20]])}));return function(){return a.apply(this,arguments)}}()},get promises(){if("every"!==a)throw new Error("[ERROR] | task-handler | \"ref.promises()\" may only be used with iterative tasks such as every and everyNow, but tried with \"".concat(a,"\" task with ID: \"").concat(b,"\""));return function(){var a=_wrapAsyncGenerator(regeneratorRuntime.mark(function a(){return regeneratorRuntime.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:a.prev=0;case 1:if(!k.status.complete){a.next=4;break}return a.abrupt("break",13);case 4:return f||j(),a.next=7,_awaitAsyncGenerator(f);case 7:return a.next=9,k;case 9:g=void 0,f=void 0,a.next=1;break;case 13:return a.abrupt("return",k);case 14:return a.prev=14,g=void 0,f=void 0,a.finish(14);case 18:case"end":return a.stop();}},a,this,[[0,,14,18]])}));return function(){return a.apply(this,arguments)}}()},status:{complete:!1,error:!1,cancelled:!1}},_defineProperty(e,_constants.TASK_CANCELLED,function(a){k.status.complete||(h=_constants.TASK_CANCELLED,k.status.cancelled=!0,k.status.complete=!0,g&&g[0](k),i&&("function"==typeof i.cancelled?a.push(i.cancelled()):"production"!==process.env.NODE_ENV&&console.warn("[WARN] | task-handler | Async Job \"".concat(b,"\" was cancelled but provided no \"cancelled\" handler."))))}),_defineProperty(e,_constants.EXECUTE_RESULT,function(a,b){if(!k.status.complete&&(h=b,"every"!==k.type&&(k.status.complete=!0),g)){if(a){var c="object"===_typeof(a)?a:new Error(a);return c.taskRef=k,g[1](c)}return g[0](k)}}),_defineProperty(e,"id",b),_defineProperty(e,"type",a),_defineProperty(e,"task",c),_defineProperty(e,"resolve",function b(a){return k[_constants.EXECUTE_RESULT](void 0,a)}),_defineProperty(e,"reject",function b(a){return k[_constants.EXECUTE_RESULT](a)}),_defineProperty(e,"cancel",function a(){h=_constants.TASK_CANCELLED,k.status.cancelled=!0,c.cancel(b)}),e);return d&&(i=d[0].apply(k,d[1]),k.promise().catch(_constants.NOOP),i.start.call(k,k)),Object.freeze(k)}function createTaskHandler(){function a(){return d?d:(d=(0,_defer.default)(e),d)}function b(a,b){var c=e.get(a);if(c){var d=_slicedToArray(c,2),f=d[0],g=d[1];g(),e.delete(a),f[_constants.TASK_CANCELLED](b)}}function c(a,b,c){try{var d="function"==typeof b?b.apply(void 0,_toConsumableArray(c)):void 0;a[_constants.EXECUTE_RESULT](void 0,d)}catch(b){a[_constants.EXECUTE_RESULT](b)}}var d,e=new Map,f=Object.freeze({get size(){return e.size},after:function l(a,b,d){for(var g=createTaskRef("after",a,f),h=arguments.length,i=Array(3<h?h-3:0),j=3;j<h;j++)i[j-3]=arguments[j];var k=setTimeout(c,b,g,d,i);return e.set(a,[g,function(){return clearTimeout(k)}]),g},defer:function l(b,d){for(var g=arguments.length,h=Array(2<g?g-2:0),i=2;i<g;i++)h[i-2]=arguments[i];var j=createTaskRef("defer",b,f),k=a().add(j,function(){return c(j,d,h)});return e.set(b,[j,function(){return k()}]),j},every:function l(a,b,d){for(var g=createTaskRef("every",a,f),h=arguments.length,i=Array(3<h?h-3:0),j=3;j<h;j++)i[j-3]=arguments[j];var k=setInterval(c,b,g,d,i);return e.set(a,[g,function(){return clearInterval(k)}]),g},everyNow:function n(b,d,g){for(var h=arguments.length,i=Array(3<h?h-3:0),j=3;j<h;j++)i[j-3]=arguments[j];var k=createTaskRef("every",b,f),l=setInterval(c,d,k,g,i),m=a().add(b,function(){return c(k,g,i)});return e.set(b,[k,function(){clearInterval(l),m()}]),k},job:function i(a,b){for(var c=arguments.length,d=Array(2<c?c-2:0),g=2;g<c;g++)d[g-2]=arguments[g];var h=createTaskRef("job",a,f,[b,d||_constants.STATIC_EMPTY_ARRAY]);return e.set(a,[h,_constants.NOOP]),h},cancel:function f(){for(var a=[],c=arguments.length,d=Array(c),e=0;e<c;e++)d[e]=arguments[e];return d.forEach(function(c){return b(c,a)}),{promise:function b(){return Promise.all(a)}}},clear:function a(){return f.cancel.apply(f,_toConsumableArray(Array.from(e.keys())))}});return f}
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=createTaskHandler,require("core-js/modules/es6.regexp.to-string"),require("core-js/modules/es6.array.from"),require("core-js/modules/web.dom.iterable"),require("core-js/modules/es6.array.iterator"),require("core-js/modules/es6.string.iterator"),require("core-js/modules/es6.map"),require("core-js/modules/es6.object.freeze"),require("regenerator-runtime/runtime"),require("core-js/modules/es7.symbol.async-iterator"),require("core-js/modules/es6.symbol"),require("core-js/modules/es6.promise");var _constants=require("./constants"),_defer=_interopRequireDefault(require("./defer"));function _interopRequireDefault(a){return a&&a.__esModule?a:{default:a}}function _toConsumableArray(a){return _arrayWithoutHoles(a)||_iterableToArray(a)||_nonIterableSpread()}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance")}function _iterableToArray(a){if(Symbol.iterator in Object(a)||"[object Arguments]"===Object.prototype.toString.call(a))return Array.from(a)}function _arrayWithoutHoles(a){if(Array.isArray(a)){for(var b=0,c=Array(a.length);b<a.length;b++)c[b]=a[b];return c}}function _slicedToArray(a,b){return _arrayWithHoles(a)||_iterableToArrayLimit(a,b)||_nonIterableRest()}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}function _iterableToArrayLimit(a,b){var c=[],d=!0,e=!1,f=void 0;try{for(var g,h=a[Symbol.iterator]();!(d=(g=h.next()).done)&&(c.push(g.value),!(b&&c.length===b));d=!0);}catch(a){e=!0,f=a}finally{try{d||null==h["return"]||h["return"]()}finally{if(e)throw f}}return c}function _arrayWithHoles(a){if(Array.isArray(a))return a}function _defineProperty(a,b,c){return b in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _typeof(a){return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},_typeof(a)}function asyncGeneratorStep(a,b,c,d,e,f,g){try{var h=a[f](g),i=h.value}catch(a){return void c(a)}h.done?b(i):Promise.resolve(i).then(d,e)}function _asyncToGenerator(a){return function(){var b=this,c=arguments;return new Promise(function(d,e){function f(a){asyncGeneratorStep(h,d,e,f,g,"next",a)}function g(a){asyncGeneratorStep(h,d,e,f,g,"throw",a)}var h=a.apply(b,c);f(void 0)})}}function _awaitAsyncGenerator(a){return new _AwaitValue(a)}function _wrapAsyncGenerator(a){return function(){return new _AsyncGenerator(a.apply(this,arguments))}}function _AsyncGenerator(a){function b(d,e){try{var f=a[d](e),g=f.value,h=g instanceof _AwaitValue;Promise.resolve(h?g.wrapped:g).then(function(a){return h?void b("next",a):void c(f.done?"return":"normal",a)},function(a){b("throw",a)})}catch(a){c("throw",a)}}function c(a,c){switch(a){case"return":d.resolve({value:c,done:!0});break;case"throw":d.reject(c);break;default:d.resolve({value:c,done:!1});}d=d.next,d?b(d.key,d.arg):e=null}var d,e;this._invoke=function(a,c){return new Promise(function(f,g){var h={key:a,arg:c,resolve:f,reject:g,next:null};e?e=e.next=h:(d=e=h,b(a,c))})},"function"!=typeof a.return&&(this.return=void 0)}"function"==typeof Symbol&&Symbol.asyncIterator&&(_AsyncGenerator.prototype[Symbol.asyncIterator]=function(){return this}),_AsyncGenerator.prototype.next=function(a){return this._invoke("next",a)},_AsyncGenerator.prototype.throw=function(a){return this._invoke("throw",a)},_AsyncGenerator.prototype.return=function(a){return this._invoke("return",a)};function _AwaitValue(a){this.wrapped=a}function createTaskRef(a,b,c,d){var e;c.cancel(b);var f,g,h,i,j=function(){return f?f:(f=new Promise(function(a,b){g=[a,b]}),f)},k=(e={get result(){return k.status.complete?h:void 0},get promise(){return function(){var a=_asyncToGenerator(regeneratorRuntime.mark(function a(){var b;return regeneratorRuntime.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:if(a.prev=0,!k.status.complete){a.next=5;break}if(!k.status.error){a.next=4;break}throw h;case 4:return a.abrupt("return",k);case 5:return b=j(),a.next=8,b;case 8:return a.abrupt("return",k);case 9:return a.prev=9,b===f&&(g=void 0,f=void 0),a.finish(9);case 12:case"end":return a.stop();}},a,this,[[0,,9,12]])}));return function(){return a.apply(this,arguments)}}()},get promises(){if("every"!==a)throw new Error("[ERROR] | task-handler | \"ref.promises()\" may only be used with iterative tasks such as every and everyNow, but tried with \"".concat(a,"\" task with ID: \"").concat(b,"\""));return function(){var a=_wrapAsyncGenerator(regeneratorRuntime.mark(function a(){var b;return regeneratorRuntime.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:a.prev=0;case 1:if(k.status.complete){a.next=10;break}return b=j(),a.next=5,_awaitAsyncGenerator(b);case 5:return a.next=7,k;case 7:b===f&&(g=void 0,f=void 0),a.next=1;break;case 10:return a.abrupt("return",k);case 11:return a.prev=11,b===f&&(g=void 0,f=void 0),a.finish(11);case 14:case"end":return a.stop();}},a,this,[[0,,11,14]])}));return function(){return a.apply(this,arguments)}}()},status:{complete:!1,error:!1,cancelled:!1}},_defineProperty(e,_constants.TASK_CANCELLED,function(a){k.status.complete||(k.status.complete=!0,!1===k.status.error&&(h=_constants.TASK_CANCELLED,k.status.cancelled=!0,g&&g[0](k),i&&("function"==typeof i.cancelled?a.push(i.cancelled.call(k,k)):"production"!==process.env.NODE_ENV&&console.warn("[WARN] | task-handler | Async Job \"".concat(b,"\" was cancelled but provided no \"cancelled\" handler.")))))}),_defineProperty(e,_constants.EXECUTE_RESULT,function(a,b){if(!k.status.complete&&(h=b,"every"!==k.type&&(k.status.complete=!0),g)){if(a){k.status.error=!0;var c="object"===_typeof(a)?a:new Error(a);return c.taskRef=k,h=c,k.cancel(),g[1](c)}return g[0](k)}}),_defineProperty(e,"id",b),_defineProperty(e,"type",a),_defineProperty(e,"task",c),_defineProperty(e,"resolve",function b(a){return k[_constants.EXECUTE_RESULT](void 0,a)}),_defineProperty(e,"reject",function b(a){return k[_constants.EXECUTE_RESULT](a)}),_defineProperty(e,"cancel",function a(){k.status.complete||(!1===k.status.error&&(h=_constants.TASK_CANCELLED,k.status.cancelled=!0),c.cancel(b))}),e);if(d){var l=_slicedToArray(d,3),m=l[0],n=l[1],o=l[2];i=m.apply(k,n),k.promise().catch(_constants.NOOP),o.set(b,[k,_constants.NOOP]),i.start.call(k,k)}return Object.freeze(k)}function createTaskHandler(){function a(){return d?d:(d=(0,_defer.default)(e),d)}function b(a,b){var c=e.get(a);if(c){var d=_slicedToArray(c,2),f=d[0],g=d[1];g(),e.delete(a),f[_constants.TASK_CANCELLED](b)}}function c(a,b,c){try{var d="function"==typeof b?b.apply(a,c):void 0;a[_constants.EXECUTE_RESULT](void 0,d)}catch(b){a[_constants.EXECUTE_RESULT](b)}}var d,e=new Map,f=Object.freeze({get size(){return e.size},has:function d(){for(var a=arguments.length,b=Array(a),c=0;c<a;c++)b[c]=arguments[c];return b.every(function(a){return e.has(a)})},after:function l(a,b,d){for(var g=createTaskRef("after",a,f),h=arguments.length,i=Array(3<h?h-3:0),j=3;j<h;j++)i[j-3]=arguments[j];var k=setTimeout(c,b,g,d,i);return e.set(a,[g,function(){return clearTimeout(k)}]),g},defer:function l(b,d){for(var g=arguments.length,h=Array(2<g?g-2:0),i=2;i<g;i++)h[i-2]=arguments[i];var j=createTaskRef("defer",b,f),k=a().add(j,function(){return c(j,d,h)});return e.set(b,[j,function(){return k()}]),j},every:function l(a,b,d){for(var g=createTaskRef("every",a,f),h=arguments.length,i=Array(3<h?h-3:0),j=3;j<h;j++)i[j-3]=arguments[j];var k=setInterval(c,b,g,d,i);return e.set(a,[g,function(){return clearInterval(k)}]),g},everyNow:function n(b,d,g){for(var h=arguments.length,i=Array(3<h?h-3:0),j=3;j<h;j++)i[j-3]=arguments[j];var k=createTaskRef("every",b,f),l=setInterval(c,d,k,g,i),m=a().add(b,function(){return c(k,g,i)});return e.set(b,[k,function(){clearInterval(l),m()}]),k},job:function i(a,b){for(var c=arguments.length,d=Array(2<c?c-2:0),g=2;g<c;g++)d[g-2]=arguments[g];var h=createTaskRef("job",a,f,[b,d||_constants.STATIC_EMPTY_ARRAY,e]);return h},cancel:function f(){for(var a=[],c=arguments.length,d=Array(c),e=0;e<c;e++)d[e]=arguments[e];return d.forEach(function(c){return b(c,a)}),{promise:function b(){return Promise.all(a)}}},clear:function a(){return f.cancel.apply(f,_toConsumableArray(Array.from(e.keys())))}});return f}
{
"name": "task-handler",
"version": "2.1.0",
"version": "2.2.0",
"description": "Handle Javascript Timers in a manageable way",

@@ -35,3 +35,3 @@ "main": "dist/index.js",

"flow": "flow",
"prepublishOnly": "npm-run-all build",
"prepublishOnly": "npm-run-all coverage build",
"test": "cross-env NODE_ENV=test nyc mocha --require @babel/register --recursive ./tests/tests/*.js",

@@ -38,0 +38,0 @@ "try": "babel-node ./tests/quick-test"

@@ -9,3 +9,2 @@ # task-handler

[![license](https://img.shields.io/github/license/odo-network/task-handler.svg)](https://github.com/odo-network/task-handler)
[![npm bundle size (minified + gzip)](https://img.shields.io/bundlephobia/minzip/task-handler.svg)](https://github.com/odo-network/task-handler)

@@ -108,7 +107,9 @@ A simple, dependency-free task scheduling manager that makes it easy to handle tasks like a boss.

Interval tasks such as `every` and `everyNow` return `async iterators` when their `.promise()` function is called. This allows us to utilize the handy `for await... of` feature of JS.
Interval tasks such as `every` and `everyNow` return `async iterators` when their `.promises()` function is called. This allows us to utilize the handy `for await... of` feature of JS.
> **IMPORTANT:** Notice that `every` and `everyNow` use `.promises()` and now `.promise()`. This is to allow for type safety. These tasks will error if `.promise()` is called on them.
```js
async function intervalForAwait() {
for await (const ref of task.every("everyID", 1000).promise()) {
for await (const ref of task.every("everyID", 1000).promises()) {
console.log("Next Tick");

@@ -123,3 +124,3 @@ // based on some logic...

async function intervalAwait() {
const iter = task.every("everyID", 1000).promise();
const iter = task.every("everyID", 1000).promises();
let done = false;

@@ -126,0 +127,0 @@ let ref;

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