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

asyncbox

Package Overview
Dependencies
Maintainers
2
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

asyncbox - npm Package Compare versions

Comparing version 2.9.4 to 3.0.0

build/lib/asyncbox.js.map

2

build/lib/asyncbox.d.ts

@@ -126,3 +126,3 @@ /**

export function longSleep(ms: number, { thresholdMs, intervalMs, progressCb, }?: LongSleepOptions | undefined): Promise<void>;
import B from "bluebird";
import B from 'bluebird';
//# sourceMappingURL=asyncbox.d.ts.map
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.asyncfilter = asyncfilter;
exports.asyncify = asyncify;
exports.asyncmap = asyncmap;
exports.longSleep = longSleep;
exports.nodeify = nodeify;
exports.nodeifyAll = nodeifyAll;
exports.parallel = void 0;
exports.retry = retry;
exports.retryInterval = retryInterval;
exports.sleep = sleep;
exports.waitForCondition = waitForCondition;
require("source-map-support/register");
var _bluebird = _interopRequireDefault(require("bluebird"));
var _lodash = _interopRequireDefault(require("lodash"));
const LONG_SLEEP_THRESHOLD = 5000;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.longSleep = exports.waitForCondition = exports.asyncfilter = exports.asyncmap = exports.parallel = exports.asyncify = exports.retryInterval = exports.nodeifyAll = exports.nodeify = exports.retry = exports.sleep = void 0;
const bluebird_1 = __importDefault(require("bluebird"));
const lodash_1 = __importDefault(require("lodash"));
const LONG_SLEEP_THRESHOLD = 5000; // anything over 5000ms will turn into a spin
/**
* An async/await version of setTimeout
* @param {number} ms
* @returns {Promise<void>}
*/
async function sleep(ms) {
return await _bluebird.default.delay(ms);
return await bluebird_1.default.delay(ms);
}
async function longSleep(ms, {
thresholdMs = LONG_SLEEP_THRESHOLD,
intervalMs = 1000,
progressCb = null
} = {}) {
if (ms < thresholdMs) {
return await sleep(ms);
}
const endAt = Date.now() + ms;
let timeLeft;
let elapsedMs = 0;
do {
const pre = Date.now();
await sleep(intervalMs);
const post = Date.now();
timeLeft = endAt - post;
elapsedMs = elapsedMs + (post - pre);
if (_lodash.default.isFunction(progressCb)) {
progressCb({
elapsedMs,
timeLeft,
progress: elapsedMs / ms
});
exports.sleep = sleep;
/**
* Sometimes `Promise.delay` or `setTimeout` are inaccurate for large wait
* times. To safely wait for these long times (e.g. in the 5+ minute range), you
* can use `longSleep`.
*
* sYou can also pass a `progressCb` option which is a callback function that
* receives an object with the properties `elapsedMs`, `timeLeft`, and
* `progress`. This will be called on every wait interval so you can do your
* wait logging or whatever.
* @param {number} ms
* @param {LongSleepOptions} [opts]
* @returns {Promise<void>}
*/
async function longSleep(ms, { thresholdMs = LONG_SLEEP_THRESHOLD, intervalMs = 1000, progressCb = null, } = {}) {
if (ms < thresholdMs) {
return await sleep(ms);
}
} while (timeLeft > 0);
const endAt = Date.now() + ms;
let timeLeft;
let elapsedMs = 0;
do {
const pre = Date.now();
await sleep(intervalMs);
const post = Date.now();
timeLeft = endAt - post;
elapsedMs = elapsedMs + (post - pre);
if (lodash_1.default.isFunction(progressCb)) {
progressCb({ elapsedMs, timeLeft, progress: elapsedMs / ms });
}
} while (timeLeft > 0);
}
exports.longSleep = longSleep;
/**
* An async/await way of running a method until it doesn't throw an error
* @template [T=any]
* @param {number} times
* @param {(...args: any[]) => Promise<T>} fn
* @param {...any} args
* @returns {Promise<T?>}
*/
async function retry(times, fn, ...args) {
let tries = 0;
let done = false;
let res = null;
while (!done && tries < times) {
tries++;
try {
res = await fn(...args);
done = true;
} catch (err) {
if (tries >= times) {
throw err;
}
let tries = 0;
let done = false;
let res = null;
while (!done && tries < times) {
tries++;
try {
res = await fn(...args);
done = true;
}
catch (err) {
if (tries >= times) {
throw err;
}
}
}
}
return res;
return res;
}
exports.retry = retry;
/**
* You can also use `retryInterval` to add a sleep in between retries. This can
* be useful if you want to throttle how fast we retry.
* @template [T=any]
* @param {number} times
* @param {number} sleepMs
* @param {(...args: any[]) => Promise<T>} fn
* @param {...any} args
* @returns {Promise<T?>}
*/
async function retryInterval(times, sleepMs, fn, ...args) {
let count = 0;
let wrapped = async () => {
count++;
let res;
try {
res = await fn(...args);
} catch (e) {
if (count !== times) {
await sleep(sleepMs);
}
throw e;
}
return res;
};
return await retry(times, wrapped);
let count = 0;
let wrapped = async () => {
count++;
let res;
try {
res = await fn(...args);
}
catch (e) {
// do not pause when finished the last retry
if (count !== times) {
await sleep(sleepMs);
}
throw e;
}
return res;
};
return await retry(times, wrapped);
}
const parallel = _bluebird.default.all;
exports.retryInterval = retryInterval;
const parallel = bluebird_1.default.all;
exports.parallel = parallel;
/**
* Export async functions (Promises) and import this with your ES5 code to use
* it with Node.
* @template [R=any]
* @param {any} promisey
* @param {(err: any, value?: R) => void} cb
* @returns {Promise<R>}
*/
function nodeify(promisey, cb) {
return _bluebird.default.resolve(promisey).nodeify(cb);
return bluebird_1.default.resolve(promisey).nodeify(cb);
}
exports.nodeify = nodeify;
/**
* Node-ify an entire object of `Promise`-returning functions
* @param {Record<string,(...args: any[]) => any>} promiseyMap
* @returns {Record<string,(...args: any[])=>void>}
*/
function nodeifyAll(promiseyMap) {
let cbMap = {};
for (const [name, fn] of _lodash.default.toPairs(promiseyMap)) {
cbMap[name] = function (...args) {
const _cb = args.slice(-1)[0];
args = args.slice(0, -1);
nodeify(fn(...args), _cb);
};
}
return cbMap;
/** @type {Record<string,(...args: any[])=>void>} */
let cbMap = {};
for (const [name, fn] of lodash_1.default.toPairs(promiseyMap)) {
cbMap[name] = function (...args) {
const _cb = args.slice(-1)[0];
args = args.slice(0, -1);
nodeify(fn(...args), _cb);
};
}
return cbMap;
}
exports.nodeifyAll = nodeifyAll;
/**
* @param {(...args: any[]) => any|Promise<any>} fn
* @param {...any} args
*/
function asyncify(fn, ...args) {
_bluebird.default.resolve(fn(...args)).done();
bluebird_1.default.resolve(fn(...args)).done();
}
exports.asyncify = asyncify;
/**
* Similar to `Array.prototype.map`; runs in serial
* @param {any[]} coll
* @param {(value: any) => any|Promise<any>} mapper
* @returns {Promise<any[]>}
*/
async function asyncmap(coll, mapper, runInParallel = true) {
if (runInParallel) {
return parallel(coll.map(mapper));
}
let newColl = [];
for (let item of coll) {
newColl.push(await mapper(item));
}
return newColl;
if (runInParallel) {
return parallel(coll.map(mapper));
}
let newColl = [];
for (let item of coll) {
newColl.push(await mapper(item));
}
return newColl;
}
exports.asyncmap = asyncmap;
/**
* Similar to `Array.prototype.filter`
* @param {any[]} coll
* @param {(value: any) => any|Promise<any>} filter
* @param {boolean} runInParallel
* @returns {Promise<any[]>}
*/
async function asyncfilter(coll, filter, runInParallel = true) {
let newColl = [];
if (runInParallel) {
let bools = await parallel(coll.map(filter));
for (let i = 0; i < coll.length; i++) {
if (bools[i]) {
newColl.push(coll[i]);
}
let newColl = [];
if (runInParallel) {
let bools = await parallel(coll.map(filter));
for (let i = 0; i < coll.length; i++) {
if (bools[i]) {
newColl.push(coll[i]);
}
}
}
} else {
for (let item of coll) {
if (await filter(item)) {
newColl.push(item);
}
else {
for (let item of coll) {
if (await filter(item)) {
newColl.push(item);
}
}
}
}
return newColl;
return newColl;
}
exports.asyncfilter = asyncfilter;
/**
* Takes a condition (a function returning a boolean or boolean promise), and
* waits until the condition is true.
*
* Throws a `/Condition unmet/` error if the condition has not been satisfied
* within the allocated time, unless an error is provided in the options, as the
* `error` property, which is either thrown itself, or used as the message.
*
* The condition result is returned if it is not falsy. If the condition throws an
* error then this exception will be immediately passed through.
*
* The default options are: `{ waitMs: 5000, intervalMs: 500 }`
* @template T
* @param {() => Promise<T>|T} condFn
* @param {WaitForConditionOptions} [options]
* @returns {Promise<T>}
*/
async function waitForCondition(condFn, options = {}) {
const opts = _lodash.default.defaults(options, {
waitMs: 5000,
intervalMs: 500
});
const debug = opts.logger ? opts.logger.debug.bind(opts.logger) : _lodash.default.noop;
const error = opts.error;
const begunAt = Date.now();
const endAt = begunAt + opts.waitMs;
const spin = async function spin() {
const result = await condFn();
if (result) {
return result;
}
const now = Date.now();
const waited = now - begunAt;
const remainingTime = endAt - now;
if (now < endAt) {
debug(`Waited for ${waited} ms so far`);
await _bluebird.default.delay(Math.min(opts.intervalMs, remainingTime));
return await spin();
}
throw error ? _lodash.default.isString(error) ? new Error(error) : error : new Error(`Condition unmet after ${waited} ms. Timing out.`);
};
return await spin();
}require('source-map-support').install();
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibGliL2FzeW5jYm94LmpzIiwibmFtZXMiOlsiTE9OR19TTEVFUF9USFJFU0hPTEQiLCJzbGVlcCIsIm1zIiwiQiIsImRlbGF5IiwibG9uZ1NsZWVwIiwidGhyZXNob2xkTXMiLCJpbnRlcnZhbE1zIiwicHJvZ3Jlc3NDYiIsImVuZEF0IiwiRGF0ZSIsIm5vdyIsInRpbWVMZWZ0IiwiZWxhcHNlZE1zIiwicHJlIiwicG9zdCIsIl8iLCJpc0Z1bmN0aW9uIiwicHJvZ3Jlc3MiLCJyZXRyeSIsInRpbWVzIiwiZm4iLCJhcmdzIiwidHJpZXMiLCJkb25lIiwicmVzIiwiZXJyIiwicmV0cnlJbnRlcnZhbCIsInNsZWVwTXMiLCJjb3VudCIsIndyYXBwZWQiLCJlIiwicGFyYWxsZWwiLCJhbGwiLCJub2RlaWZ5IiwicHJvbWlzZXkiLCJjYiIsInJlc29sdmUiLCJub2RlaWZ5QWxsIiwicHJvbWlzZXlNYXAiLCJjYk1hcCIsIm5hbWUiLCJ0b1BhaXJzIiwiX2NiIiwic2xpY2UiLCJhc3luY2lmeSIsImFzeW5jbWFwIiwiY29sbCIsIm1hcHBlciIsInJ1bkluUGFyYWxsZWwiLCJtYXAiLCJuZXdDb2xsIiwiaXRlbSIsInB1c2giLCJhc3luY2ZpbHRlciIsImZpbHRlciIsImJvb2xzIiwiaSIsImx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RUFBRW1FLGFBQWEsQ0FBQyxDQUFDO01BQ3ZELE9BQU8sTUFBTUgsSUFBSSxFQUFFO0lBQ3JCO0lBRUEsTUFBTUYsS0FBSyxHQUNOckQsZUFBQyxDQUFDNkQsUUFBUSxDQUFDUixLQUFLLENBQUMsR0FBRyxJQUFJUyxLQUFLLENBQUNULEtBQUssQ0FBQyxHQUFHQSxLQUFLLEdBQzdDLElBQUlTLEtBQUssQ0FBRSx5QkFBd0JMLE1BQU8sa0JBQWlCLENBQUM7RUFDbEUsQ0FBQztFQUNELE9BQU8sTUFBTUYsSUFBSSxFQUFFO0FBQ3JCIn0=
/** @type {WaitForConditionOptions & {waitMs: number, intervalMs: number}} */
const opts = lodash_1.default.defaults(options, {
waitMs: 5000,
intervalMs: 500,
});
const debug = opts.logger ? opts.logger.debug.bind(opts.logger) : lodash_1.default.noop;
const error = opts.error;
const begunAt = Date.now();
const endAt = begunAt + opts.waitMs;
/** @returns {Promise<T>} */
const spin = async function spin() {
const result = await condFn();
if (result) {
return result;
}
const now = Date.now();
const waited = now - begunAt;
const remainingTime = endAt - now;
if (now < endAt) {
debug(`Waited for ${waited} ms so far`);
await bluebird_1.default.delay(Math.min(opts.intervalMs, remainingTime));
return await spin();
}
// if there is an error option, it is either a string message or an error itself
throw error
? (lodash_1.default.isString(error) ? new Error(error) : error)
: new Error(`Condition unmet after ${waited} ms. Timing out.`);
};
return await spin();
}
exports.waitForCondition = waitForCondition;
/**
* Options for {@link waitForCondition}
* @typedef WaitForConditionOptions
* @property {number} [waitMs]
* @property {number} [intervalMs]
* @property {{debug: (...args: any[]) => void}} [logger]
* @property {string|Error} [error]
*/
/**
* Options for {@link longSleep}
* @typedef LongSleepOptions
* @property {number} [thresholdMs]
* @property {number} [intervalMs]
* @property {ProgressCallback?} [progressCb]
*/
/**
* Parameter provided to a {@link ProgressCallback}
* @typedef Progress
* @property {number} elapsedMs
* @property {number} timeLeft
* @property {number} progress
*/
/**
* Progress callback for {@link longSleep}
* @callback ProgressCallback
* @param {Progress} progress
* @returns {void}
*/
//# sourceMappingURL=asyncbox.js.map

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

// transpile:main
import B from 'bluebird';

@@ -4,0 +2,0 @@ import _ from 'lodash';

@@ -9,3 +9,3 @@ {

],
"version": "2.9.4",
"version": "3.0.0",
"author": "jlipps@gmail.com",

@@ -21,3 +21,3 @@ "license": "Apache-2.0",

"engines": {
"node": ">=10"
"node": ">=16"
},

@@ -34,31 +34,39 @@ "main": "./build/lib/asyncbox.js",

"dependencies": {
"@babel/runtime": "^7.0.0",
"bluebird": "^3.5.1",
"lodash": "^4.17.4",
"source-map-support": "^0.5.5",
"@types/bluebird": "^3.5.37"
"source-map-support": "^0.x"
},
"scripts": {
"clean": "rm -rf node_modules && rm -f package-lock.json && npm install",
"prepare": "gulp prepublish && tsc",
"test": "gulp once",
"e2e-test": "gulp e2e-test",
"build": "gulp transpile && tsc",
"lint": "gulp eslint",
"watch": "gulp watch"
"build": "tsc -b",
"clean": "npm run build -- --clean",
"rebuild": "npm run clean; npm run build",
"dev": "npm run build -- --watch",
"prepare": "npm run rebuild",
"test": "mocha --exit --timeout 1m \"./test/**/*-specs.js\"",
"lint": "eslint .",
"watch": "npm run dev"
},
"devDependencies": {
"@appium/eslint-config-appium": "^8.0.4",
"@appium/eslint-config-appium-ts": "^0.x",
"@appium/tsconfig": "^0.x",
"@types/bluebird": "^3.5.37",
"@types/lodash": "^4.14.189",
"ajv": "^6.5.3",
"appium-gulp-plugins": "^4.0.0",
"chai": "4.2.0",
"@types/node": "^20.4.7",
"@typescript-eslint/eslint-plugin": "^6.9.0",
"@typescript-eslint/parser": "^6.9.0",
"chai": "^4.2.0",
"chai-as-promised": "^7.1.1",
"eslint-config-appium": "^4.0.0",
"gulp": "^4.0.0",
"request": "^2.47.0",
"should": "^13.2.1",
"sinon": "^11.1.2",
"typescript": "~4.7.0"
"eslint": "^8.46.0",
"eslint-config-prettier": "^9.0.0",
"eslint-import-resolver-typescript": "^3.5.5",
"eslint-plugin-import": "^2.28.0",
"eslint-plugin-mocha": "^10.1.0",
"eslint-plugin-promise": "^6.1.1",
"mocha": "^10.0.0",
"sinon": "^16.0.0",
"ts-node": "^10.9.1",
"typescript": "^5.1.6"
},
"types": "./build/lib/asyncbox.d.ts"
}

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