appolo-utils
Advanced tools
Comparing version 0.0.27 to 0.0.28
@@ -107,2 +107,39 @@ "use strict"; | ||
} | ||
static some(promises, counter = 1) { | ||
return new Promise((resolve) => { | ||
let settled = []; | ||
counter = Math.min(Math.max(Math.floor(counter), 1), promises.length); | ||
for (let i = 0; i < promises.length; i++) { | ||
promises[i] | ||
.then(value => (settled.push({ status: "fulfilled", value }) === counter) && resolve(settled)) | ||
.catch(reason => (settled.push({ status: "rejected", reason }) === counter) && resolve(settled)); | ||
} | ||
}); | ||
} | ||
static someResolved(promises, counter = 1) { | ||
return new Promise((resolve, reject) => { | ||
let resolved = [], rejected = []; | ||
counter = Math.min(Math.max(Math.floor(counter), 1), promises.length); | ||
for (let i = 0; i < promises.length; i++) { | ||
promises[i] | ||
.then(value => (resolved.push({ status: "fulfilled", value }) === counter | ||
|| resolved.length + rejected.length === promises.length) && resolve(resolved)) | ||
.catch(reason => (rejected.push({ status: "rejected", reason }) + resolved.length === promises.length) | ||
&& resolve(resolved)); | ||
} | ||
}); | ||
} | ||
static someRejected(promises, counter = 1) { | ||
return new Promise((resolve, reject) => { | ||
let resolved = [], rejected = []; | ||
counter = Math.min(Math.max(Math.floor(counter), 1), promises.length); | ||
for (let i = 0; i < promises.length; i++) { | ||
promises[i] | ||
.then(value => (resolved.push({ status: "fulfilled", value }) + rejected.length === promises.length) | ||
&& resolve(rejected)) | ||
.catch(reason => (rejected.push({ status: "rejected", reason }) === counter | ||
|| resolved.length + rejected.length === promises.length) && resolve(rejected)); | ||
} | ||
}); | ||
} | ||
} | ||
@@ -109,0 +146,0 @@ exports.Promises = Promises; |
@@ -130,3 +130,3 @@ type Resolvable<R> = R | PromiseLike<R> | ||
public static allSettled<T>(promises: Promise<T>[]):Promise< ({ status: "fulfilled"; value: T; } | { status: "rejected"; reason: any; })[]> { | ||
public static allSettled<T>(promises: Promise<T>[]): Promise<({ status: "fulfilled"; value: T; } | { status: "rejected"; reason: any; })[]> { | ||
@@ -145,2 +145,51 @@ let settled = []; | ||
} | ||
public static some<T>(promises: Promise<T>[], counter: number = 1): Promise<({ status: "fulfilled"; value: T; } | { status: "rejected"; reason: any; })[]> { | ||
return new Promise((resolve) => { | ||
let settled = []; | ||
counter = Math.min(Math.max(Math.floor(counter), 1), promises.length); | ||
for (let i = 0; i < promises.length; i++) { | ||
promises[i] | ||
.then(value => (settled.push({status: "fulfilled", value}) === counter) && resolve(settled)) | ||
.catch(reason => (settled.push({status: "rejected", reason}) === counter) && resolve(settled)); | ||
} | ||
}) | ||
} | ||
public static someResolved<T>(promises: Promise<T>[], counter: number = 1): Promise<({ status: "fulfilled"; value: T; })[]> { | ||
return new Promise((resolve, reject) => { | ||
let resolved = [], rejected = []; | ||
counter = Math.min(Math.max(Math.floor(counter), 1), promises.length); | ||
for (let i = 0; i < promises.length; i++) { | ||
promises[i] | ||
.then(value => (resolved.push({status: "fulfilled", value}) === counter | ||
|| resolved.length + rejected.length === promises.length) && resolve(resolved)) | ||
.catch(reason => (rejected.push({status: "rejected", reason}) + resolved.length === promises.length) | ||
&& resolve(resolved)) | ||
} | ||
}) | ||
} | ||
public static someRejected<T>(promises: Promise<T>[], counter: number = 1): Promise<({ status: "fulfilled"; value: T; })[]> { | ||
return new Promise((resolve, reject) => { | ||
let resolved = [], rejected = []; | ||
counter = Math.min(Math.max(Math.floor(counter), 1), promises.length); | ||
for (let i = 0; i < promises.length; i++) { | ||
promises[i] | ||
.then(value => (resolved.push({status: "fulfilled", value}) + rejected.length === promises.length) | ||
&& resolve(rejected)) | ||
.catch(reason => (rejected.push({status: "rejected", reason}) === counter | ||
|| resolved.length + rejected.length === promises.length) && resolve(rejected)) | ||
} | ||
}) | ||
} | ||
} | ||
@@ -147,0 +196,0 @@ |
@@ -17,3 +17,3 @@ { | ||
"main": "./index.js", | ||
"version": "0.0.27", | ||
"version": "0.0.28", | ||
"license": "MIT", | ||
@@ -20,0 +20,0 @@ "repository": { |
Sorry, the diff of this file is not supported yet
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
69632
1240