Comparing version 15.0.2 to 15.1.0
# Changelog | ||
## 15.1.0 | ||
add decorateForceSequential | ||
## 15.0.1 | ||
@@ -7,3 +11,2 @@ | ||
## 15.0.0 | ||
@@ -13,3 +16,2 @@ | ||
## 14.2.0 | ||
@@ -16,0 +18,0 @@ |
{ | ||
"name": "utilsac", | ||
"version": "15.0.2", | ||
"version": "15.1.0", | ||
"description": "Utility functions", | ||
@@ -5,0 +5,0 @@ "license": "CC0-1.0", |
@@ -20,7 +20,8 @@ # [utilsac](https://github.com/GrosSacASac/utilsac) | ||
throttledWithLast, | ||
chainPromiseNTimes, | ||
chainPromises, | ||
somePromisesParallel, | ||
chainRequestAnimationFrame, | ||
decorateForceSequential, | ||
doNTimes, | ||
chainPromiseNTimes, | ||
timeFunction, | ||
@@ -27,0 +28,0 @@ timePromise, |
@@ -5,7 +5,8 @@ export { | ||
throttledWithLast, | ||
chainPromiseNTimes, | ||
chainPromises, | ||
somePromisesParallel, | ||
chainRequestAnimationFrame, | ||
decorateForceSequential, | ||
doNTimes, | ||
chainPromiseNTimes, | ||
timeFunction, | ||
@@ -116,5 +117,26 @@ timePromise, | ||
const decorateForceSequential = function (promiseCreator) { | ||
/* forces a function that returns a promise to be sequential | ||
useful for fs for example */ | ||
let lastPromise = Promise.resolve(); | ||
return async function (...x) { | ||
const promiseWeAreWaitingFor = lastPromise; | ||
let currentPromise; | ||
let callback; | ||
// we need to change lastPromise before await anything, | ||
// otherwise 2 calls might wait the same thing | ||
lastPromise = new Promise(function (resolve) { | ||
callback = resolve; | ||
}); | ||
await promiseWeAreWaitingFor; | ||
currentPromise = promiseCreator(...x); | ||
currentPromise.then(callback).catch(callback); | ||
return currentPromise; | ||
}; | ||
}; | ||
const somePromisesParallel = function (promiseCreators, x = 10) { | ||
/* same as chainPromises except it will run up to x amount of | ||
promise in paraell */ | ||
promise in parallel */ | ||
const {length} = promiseCreators; | ||
@@ -121,0 +143,0 @@ const values = []; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
39929
805
161