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

@aspiesoft/async-extra

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@aspiesoft/async-extra - npm Package Compare versions

Comparing version 0.2.6 to 0.2.7

2

main.min.js

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

const t=t=>new Promise(e=>setTimeout(e,t));async function e(e,n=1e4,i=10){if(i<1&&(i=1),"function"==typeof e){e()&&e();let o=0;for(;!(e()||(await t(i),o++,!1!==n&&o>=n/i)););return e()}return console.error("TypeError: waitForValue expects a function with a return value"),!1}function n(t,e){if("string"==typeof t&&(t=[t]),t&&"object"==typeof t){let n=Object.keys(t);for(let i=0;i<n.length;i++)e(t[n[i]],n[i],t)}else if(t&&Array.isArray(t))for(let n=0;n<t.length;n++)e(t[n],n,t)}module.exports={function:function(){let t={timeout:1e4,checkInterval:10},i=0,o=0,r=[];function c(e,n){"object"==typeof e?Object.assign(t,e):"string"==typeof e&&(t[e]=n)}function u(){"object"==typeof arguments[0]&&"function"!=typeof arguments[0]&&Object.assign(t,arguments[0]);let e=i;i+=arguments.length,n(arguments,async(t,n)=>{n=Number(n)+Number(e),"function"==typeof t&&(r[n]=await t()),o++})}function f(t,e){i++,(async()=>{r[t]=await e(),o++})()}function s(n){return e(()=>o>=i,t.timeout,t.checkInterval).then(()=>{const t=o>=i;return"function"==typeof n&&r.forEach((e,i)=>{void 0!==e&&n(e,i,r,t)}),{results:r,finished:t,unfinished:i-o}})}async function a(){return await e(()=>o>=i,t.timeout,t.checkInterval),!(o<i)&&i-o}async function l(){return await e(()=>o>=i,t.timeout,t.checkInterval),{results:r,finished:o>=i,unfinished:i-o}}function y(){return{results:r,finished:o>=i,unfinished:i-o}}function h(){return e(()=>o>=1,t.timeout,t.checkInterval).then(()=>{const t=o>=i;let e=void 0,c=!1;return n(r,(t,n)=>{void 0===e&&void 0!==t&&(e=t,c=n)}),{result:e,index:c,results:r,finished:t,unfinished:i-o}})}function d(n=0){return e(()=>void 0!==r[n],t.timeout,t.checkInterval).then(()=>({result:r[n],index:n}))}return arguments&&arguments.length>0&&("object"==typeof arguments[0]&&"function"!=typeof arguments[0]&&Object.assign(t,arguments[0]),t.resultObject&&(r={}),i=arguments.length,n(arguments,async(t,e)=>{"function"==typeof t&&(r[e]=await t()),o++})),{options:c,add:u,addIndex:f,onFinish:s,wait:a,result:l,resultSync:y,firstResult:h,resultIndex:d}},forEach:function(t,i,o){if(!t||"function"!=typeof i)return;"object"==typeof t||Array.isArray(t)||(t=[t]);let r={timeout:1e4,checkInterval:10};"object"==typeof o&&Object.assign(r,o);let c=t.length;return"object"==typeof t&&(c=Object.keys(t).length),n(t,async(e,n)=>{await i(e,n,t),c--}),e(()=>c<=0,r.timeout,r.checkInterval).then(()=>({finished:c<=0,unfinished:c}))},map:function(t,i,o){if(!t||"function"!=typeof i)return;"object"==typeof t||Array.isArray(t)||(t=[t]);let r={timeout:1e4,checkInterval:10};"object"==typeof o&&Object.assign(r,o);let c=t.length;"object"==typeof t&&(c=Object.keys(t).length);let u=function(t){return Array.isArray(t)?[]:"object"==typeof t?{}:void 0}(t);return n(t,async(e,n)=>{u[n]=await i(e,n,t),c--}),e(()=>c<=0,r.timeout,r.checkInterval).then(()=>({result:u,finished:c<=0,unfinished:c}))},sleep:t,waitForValue:e};
const sleep=e=>new Promise((t=>setTimeout(t,e)));async function waitForValue(e,t=1e4,n=10){if(n<1&&(n=1),"function"==typeof e){e()&&e();let i=0;for(;!(e()||(await sleep(n),i++,!1!==t&&i>=t/n)););return e()}return console.error("TypeError: waitForValue expects a function with a return value"),!1}function forEach(e,t){if("string"==typeof e&&(e=[e]),e&&"object"==typeof e){let n=Object.keys(e);for(let i=0;i<n.length;i++)t(e[n[i]],n[i],e)}else if(e&&Array.isArray(e))for(let n=0;n<e.length;n++)t(e[n],n,e)}module.exports={function:function(){let e={timeout:1e4,checkInterval:10},t=0,n=0,i=[];return arguments&&arguments.length>0&&("object"==typeof arguments[0]&&"function"!=typeof arguments[0]&&Object.assign(e,arguments[0]),e.resultObject&&(i={}),t=arguments.length,forEach(arguments,(async(e,t)=>{"function"==typeof e&&(i[t]=await e()),n++}))),{options:function(t,n){"object"==typeof t?Object.assign(e,t):"string"==typeof t&&(e[t]=n)},add:function(){"object"==typeof arguments[0]&&"function"!=typeof arguments[0]&&Object.assign(e,arguments[0]);let o=t;t+=arguments.length,forEach(arguments,(async(e,t)=>{t=Number(t)+Number(o),"function"==typeof e&&(i[t]=await e()),n++}))},addIndex:function(e,o){t++,(async()=>{i[e]=await o(),n++})()},onFinish:function(o){return waitForValue((()=>n>=t),e.timeout,e.checkInterval).then((()=>{const e=n>=t;return"function"==typeof o&&i.forEach(((t,n)=>{void 0!==t&&o(t,n,i,e)})),{results:i,finished:e,unfinished:t-n}}))},wait:async function(){return await waitForValue((()=>n>=t),e.timeout,e.checkInterval),!(n<t)&&t-n},result:async function(){return await waitForValue((()=>n>=t),e.timeout,e.checkInterval),{results:i,finished:n>=t,unfinished:t-n}},resultSync:function(){return{results:i,finished:n>=t,unfinished:t-n}},firstResult:function(){return waitForValue((()=>n>=1),e.timeout,e.checkInterval).then((()=>{const e=n>=t;let o,r=!1;return forEach(i,((e,t)=>{void 0===o&&void 0!==e&&(o=e,r=t)})),{result:o,index:r,results:i,finished:e,unfinished:t-n}}))},resultIndex:function(t=0){return waitForValue((()=>void 0!==i[t]),e.timeout,e.checkInterval).then((()=>({result:i[t],index:t})))}}},forEach:function(e,t,n){if(!e||"function"!=typeof t)return;"object"==typeof e||Array.isArray(e)||(e=[e]);let i={timeout:1e4,checkInterval:10};"object"==typeof n&&Object.assign(i,n);let o=e.length;return"object"==typeof e&&(o=Object.keys(e).length),forEach(e,(async(n,i)=>{await t(n,i,e),o--})),waitForValue((()=>o<=0),i.timeout,i.checkInterval).then((()=>({finished:o<=0,unfinished:o})))},map:function(e,t,n){if(!e||"function"!=typeof t)return;"object"==typeof e||Array.isArray(e)||(e=[e]);let i={timeout:1e4,checkInterval:10};"object"==typeof n&&Object.assign(i,n);let o=e.length;"object"==typeof e&&(o=Object.keys(e).length);let r=function(e){return Array.isArray(e)?[]:"object"==typeof e?{}:void 0}(e);return forEach(e,(async(n,i)=>{r[i]=await t(n,i,e),o--})),waitForValue((()=>o<=0),i.timeout,i.checkInterval).then((()=>({result:r,finished:o<=0,unfinished:o})))},sleep,waitForValue};
{
"name": "@aspiesoft/async-extra",
"version": "0.2.6",
"version": "0.2.7",
"description": "Some additional functions to advance the capabilities of asynchronous code in javascript.",

@@ -30,4 +30,4 @@ "license": "MIT",

"devDependencies": {
"miniforge-js": "^1.0.0"
"miniforge-js": "^1.2.2"
}
}
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