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

@teamawesome/tiny-batch

Package Overview
Dependencies
Maintainers
0
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@teamawesome/tiny-batch - npm Package Compare versions

Comparing version 2.0.1 to 2.0.2

154

dist/tiny-batch.js
/**
* Queues a flush in the microtask queue at the first call.
*/
var microtaskScheduler = function microtaskScheduler() {
return function (queue, flush) {
const microtaskScheduler = () => {
return (queue, flush) => {
if (queue.length === 1) {

@@ -14,5 +14,5 @@ queueMicrotask(flush);

*/
var intervalScheduler = function intervalScheduler(ms) {
var timerId;
var fn = function fn(queue, flush) {
const intervalScheduler = ms => {
let timerId;
const fn = (queue, flush) => {
if (queue.length === 1) {

@@ -22,3 +22,3 @@ timerId = setInterval(flush, ms);

};
fn.stop = function () {
fn.stop = () => {
clearInterval(timerId);

@@ -31,5 +31,5 @@ };

*/
var timeoutScheduler = function timeoutScheduler(ms) {
var timerId;
var fn = function fn(queue, flush) {
const timeoutScheduler = ms => {
let timerId;
const fn = (queue, flush) => {
if (queue.length === 1) {

@@ -39,3 +39,3 @@ timerId = setTimeout(flush, ms);

};
fn.stop = function () {
fn.stop = () => {
clearTimeout(timerId);

@@ -49,4 +49,4 @@ };

*/
var amountScheduler = function amountScheduler(max) {
return function (queue, flush) {
const amountScheduler = max => {
return (queue, flush) => {
if (queue.length === max) {

@@ -58,100 +58,64 @@ flush();

function _defineProperties(e, r) {
for (var t = 0; t < r.length; t++) {
var o = r[t];
o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o);
}
}
function _createClass(e, r, t) {
return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", {
writable: !1
}), e;
}
function _toPrimitive(t, r) {
if ("object" != typeof t || !t) return t;
var e = t[Symbol.toPrimitive];
if (void 0 !== e) {
var i = e.call(t, r || "default");
if ("object" != typeof i) return i;
throw new TypeError("@@toPrimitive must return a primitive value.");
}
return ("string" === r ? String : Number)(t);
}
function _toPropertyKey(t) {
var i = _toPrimitive(t, "string");
return "symbol" == typeof i ? i : i + "";
}
var Queue = /*#__PURE__*/function () {
function Queue() {
class Queue {
constructor() {
this.args = [];
this.resolvers = [];
}
var _proto = Queue.prototype;
_proto.add = function add(args, resolve, reject) {
add(args, resolve, reject) {
this.args.push(args);
this.resolvers.push({
resolve: resolve,
reject: reject
resolve,
reject
});
};
_proto.reset = function reset() {
var args = this.args.splice(0);
var resolvers = this.resolvers.splice(0);
}
reset() {
const args = this.args.splice(0);
const resolvers = this.resolvers.splice(0);
return {
args: args,
resolvers: resolvers
args,
resolvers
};
};
_proto.isEmpty = function isEmpty() {
}
isEmpty() {
return this.args.length === 0;
};
return _createClass(Queue, [{
key: "length",
get: function get() {
return this.args.length;
}
}]);
}();
}
get length() {
return this.args.length;
}
}
function tinybatch(callback, scheduler) {
if (scheduler === void 0) {
scheduler = microtaskScheduler();
}
var queue = new Queue();
var _fn = function fn() {
var _arguments = arguments;
return new Promise(function (resolve, reject) {
queue.add([].slice.call(_arguments), resolve, reject);
scheduler(queue.args, _fn.flush);
function tinybatch(callback, scheduler = microtaskScheduler()) {
const queue = new Queue();
const fn = (...args) => {
return new Promise((resolve, reject) => {
queue.add(args, resolve, reject);
scheduler(queue.args, fn.flush);
});
};
_fn.queue = queue;
_fn.scheduler = scheduler;
_fn.flush = function () {
try {
if (queue.isEmpty()) {
return Promise.resolve();
fn.queue = queue;
fn.scheduler = scheduler;
fn.flush = async () => {
var _await$callback;
if (queue.isEmpty()) {
return;
}
const {
args,
resolvers
} = queue.reset();
const results = (_await$callback = await callback(args)) != null ? _await$callback : [];
for (let i = 0; i < resolvers.length; i++) {
const {
resolve,
reject
} = resolvers[i];
const result = results[i];
if (result instanceof Error) {
reject(result);
} else {
resolve(result);
}
var _queue$reset = queue.reset(),
args = _queue$reset.args,
resolvers = _queue$reset.resolvers;
return Promise.resolve(callback(args)).then(function (results) {
for (var i = 0; i < resolvers.length; i++) {
var _resolvers$i = resolvers[i],
resolve = _resolvers$i.resolve,
reject = _resolvers$i.reject;
var result = results[i];
if (result instanceof Error) {
reject(result);
} else {
resolve(result);
}
}
});
} catch (e) {
return Promise.reject(e);
}
};
return _fn;
return fn;
}

@@ -158,0 +122,0 @@

/**
* Queues a flush in the microtask queue at the first call.
*/
var microtaskScheduler = function microtaskScheduler() {
return function (queue, flush) {
const microtaskScheduler = () => {
return (queue, flush) => {
if (queue.length === 1) {

@@ -14,5 +14,5 @@ queueMicrotask(flush);

*/
var intervalScheduler = function intervalScheduler(ms) {
var timerId;
var fn = function fn(queue, flush) {
const intervalScheduler = ms => {
let timerId;
const fn = (queue, flush) => {
if (queue.length === 1) {

@@ -22,3 +22,3 @@ timerId = setInterval(flush, ms);

};
fn.stop = function () {
fn.stop = () => {
clearInterval(timerId);

@@ -31,5 +31,5 @@ };

*/
var timeoutScheduler = function timeoutScheduler(ms) {
var timerId;
var fn = function fn(queue, flush) {
const timeoutScheduler = ms => {
let timerId;
const fn = (queue, flush) => {
if (queue.length === 1) {

@@ -39,3 +39,3 @@ timerId = setTimeout(flush, ms);

};
fn.stop = function () {
fn.stop = () => {
clearTimeout(timerId);

@@ -49,4 +49,4 @@ };

*/
var amountScheduler = function amountScheduler(max) {
return function (queue, flush) {
const amountScheduler = max => {
return (queue, flush) => {
if (queue.length === max) {

@@ -58,100 +58,64 @@ flush();

function _defineProperties(e, r) {
for (var t = 0; t < r.length; t++) {
var o = r[t];
o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o);
}
}
function _createClass(e, r, t) {
return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", {
writable: !1
}), e;
}
function _toPrimitive(t, r) {
if ("object" != typeof t || !t) return t;
var e = t[Symbol.toPrimitive];
if (void 0 !== e) {
var i = e.call(t, r || "default");
if ("object" != typeof i) return i;
throw new TypeError("@@toPrimitive must return a primitive value.");
}
return ("string" === r ? String : Number)(t);
}
function _toPropertyKey(t) {
var i = _toPrimitive(t, "string");
return "symbol" == typeof i ? i : i + "";
}
var Queue = /*#__PURE__*/function () {
function Queue() {
class Queue {
constructor() {
this.args = [];
this.resolvers = [];
}
var _proto = Queue.prototype;
_proto.add = function add(args, resolve, reject) {
add(args, resolve, reject) {
this.args.push(args);
this.resolvers.push({
resolve: resolve,
reject: reject
resolve,
reject
});
};
_proto.reset = function reset() {
var args = this.args.splice(0);
var resolvers = this.resolvers.splice(0);
}
reset() {
const args = this.args.splice(0);
const resolvers = this.resolvers.splice(0);
return {
args: args,
resolvers: resolvers
args,
resolvers
};
};
_proto.isEmpty = function isEmpty() {
}
isEmpty() {
return this.args.length === 0;
};
return _createClass(Queue, [{
key: "length",
get: function get() {
return this.args.length;
}
}]);
}();
}
get length() {
return this.args.length;
}
}
function tinybatch(callback, scheduler) {
if (scheduler === void 0) {
scheduler = microtaskScheduler();
}
var queue = new Queue();
var _fn = function fn() {
var _arguments = arguments;
return new Promise(function (resolve, reject) {
queue.add([].slice.call(_arguments), resolve, reject);
scheduler(queue.args, _fn.flush);
function tinybatch(callback, scheduler = microtaskScheduler()) {
const queue = new Queue();
const fn = (...args) => {
return new Promise((resolve, reject) => {
queue.add(args, resolve, reject);
scheduler(queue.args, fn.flush);
});
};
_fn.queue = queue;
_fn.scheduler = scheduler;
_fn.flush = function () {
try {
if (queue.isEmpty()) {
return Promise.resolve();
fn.queue = queue;
fn.scheduler = scheduler;
fn.flush = async () => {
var _await$callback;
if (queue.isEmpty()) {
return;
}
const {
args,
resolvers
} = queue.reset();
const results = (_await$callback = await callback(args)) != null ? _await$callback : [];
for (let i = 0; i < resolvers.length; i++) {
const {
resolve,
reject
} = resolvers[i];
const result = results[i];
if (result instanceof Error) {
reject(result);
} else {
resolve(result);
}
var _queue$reset = queue.reset(),
args = _queue$reset.args,
resolvers = _queue$reset.resolvers;
return Promise.resolve(callback(args)).then(function (results) {
for (var i = 0; i < resolvers.length; i++) {
var _resolvers$i = resolvers[i],
resolve = _resolvers$i.resolve,
reject = _resolvers$i.reject;
var result = results[i];
if (result instanceof Error) {
reject(result);
} else {
resolve(result);
}
}
});
} catch (e) {
return Promise.reject(e);
}
};
return _fn;
return fn;
}

@@ -158,0 +122,0 @@

@@ -9,4 +9,4 @@ (function (global, factory) {

*/
var microtaskScheduler = function microtaskScheduler() {
return function (queue, flush) {
const microtaskScheduler = () => {
return (queue, flush) => {
if (queue.length === 1) {

@@ -20,5 +20,5 @@ queueMicrotask(flush);

*/
var intervalScheduler = function intervalScheduler(ms) {
var timerId;
var fn = function fn(queue, flush) {
const intervalScheduler = ms => {
let timerId;
const fn = (queue, flush) => {
if (queue.length === 1) {

@@ -28,3 +28,3 @@ timerId = setInterval(flush, ms);

};
fn.stop = function () {
fn.stop = () => {
clearInterval(timerId);

@@ -37,5 +37,5 @@ };

*/
var timeoutScheduler = function timeoutScheduler(ms) {
var timerId;
var fn = function fn(queue, flush) {
const timeoutScheduler = ms => {
let timerId;
const fn = (queue, flush) => {
if (queue.length === 1) {

@@ -45,3 +45,3 @@ timerId = setTimeout(flush, ms);

};
fn.stop = function () {
fn.stop = () => {
clearTimeout(timerId);

@@ -55,4 +55,4 @@ };

*/
var amountScheduler = function amountScheduler(max) {
return function (queue, flush) {
const amountScheduler = max => {
return (queue, flush) => {
if (queue.length === max) {

@@ -64,100 +64,64 @@ flush();

function _defineProperties(e, r) {
for (var t = 0; t < r.length; t++) {
var o = r[t];
o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o);
}
}
function _createClass(e, r, t) {
return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", {
writable: !1
}), e;
}
function _toPrimitive(t, r) {
if ("object" != typeof t || !t) return t;
var e = t[Symbol.toPrimitive];
if (void 0 !== e) {
var i = e.call(t, r || "default");
if ("object" != typeof i) return i;
throw new TypeError("@@toPrimitive must return a primitive value.");
}
return ("string" === r ? String : Number)(t);
}
function _toPropertyKey(t) {
var i = _toPrimitive(t, "string");
return "symbol" == typeof i ? i : i + "";
}
var Queue = /*#__PURE__*/function () {
function Queue() {
class Queue {
constructor() {
this.args = [];
this.resolvers = [];
}
var _proto = Queue.prototype;
_proto.add = function add(args, resolve, reject) {
add(args, resolve, reject) {
this.args.push(args);
this.resolvers.push({
resolve: resolve,
reject: reject
resolve,
reject
});
};
_proto.reset = function reset() {
var args = this.args.splice(0);
var resolvers = this.resolvers.splice(0);
}
reset() {
const args = this.args.splice(0);
const resolvers = this.resolvers.splice(0);
return {
args: args,
resolvers: resolvers
args,
resolvers
};
};
_proto.isEmpty = function isEmpty() {
}
isEmpty() {
return this.args.length === 0;
};
return _createClass(Queue, [{
key: "length",
get: function get() {
return this.args.length;
}
}]);
}();
}
get length() {
return this.args.length;
}
}
function tinybatch(callback, scheduler) {
if (scheduler === void 0) {
scheduler = microtaskScheduler();
}
var queue = new Queue();
var _fn = function fn() {
var _arguments = arguments;
return new Promise(function (resolve, reject) {
queue.add([].slice.call(_arguments), resolve, reject);
scheduler(queue.args, _fn.flush);
function tinybatch(callback, scheduler = microtaskScheduler()) {
const queue = new Queue();
const fn = (...args) => {
return new Promise((resolve, reject) => {
queue.add(args, resolve, reject);
scheduler(queue.args, fn.flush);
});
};
_fn.queue = queue;
_fn.scheduler = scheduler;
_fn.flush = function () {
try {
if (queue.isEmpty()) {
return Promise.resolve();
fn.queue = queue;
fn.scheduler = scheduler;
fn.flush = async () => {
var _await$callback;
if (queue.isEmpty()) {
return;
}
const {
args,
resolvers
} = queue.reset();
const results = (_await$callback = await callback(args)) != null ? _await$callback : [];
for (let i = 0; i < resolvers.length; i++) {
const {
resolve,
reject
} = resolvers[i];
const result = results[i];
if (result instanceof Error) {
reject(result);
} else {
resolve(result);
}
var _queue$reset = queue.reset(),
args = _queue$reset.args,
resolvers = _queue$reset.resolvers;
return Promise.resolve(callback(args)).then(function (results) {
for (var i = 0; i < resolvers.length; i++) {
var _resolvers$i = resolvers[i],
resolve = _resolvers$i.resolve,
reject = _resolvers$i.reject;
var result = results[i];
if (result instanceof Error) {
reject(result);
} else {
resolve(result);
}
}
});
} catch (e) {
return Promise.reject(e);
}
};
return _fn;
return fn;
}

@@ -164,0 +128,0 @@

{
"name": "@teamawesome/tiny-batch",
"version": "2.0.1",
"version": "2.0.2",
"description": "Combine individual calls to a single one.",

@@ -18,3 +18,3 @@ "keywords": [

"scripts": {
"build": "microbundle --no-compress",
"build": "microbundle --no-compress --target node",
"dev": "tsc --watch",

@@ -21,0 +21,0 @@ "lint": "eslint ./src --config ./eslint-src.config.mjs",

Sorry, the diff of this file is not supported yet

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