mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-09-22 00:50:25 +00:00
Merge pull request #16680 from natesilva/p-settle
Added types for p-settle
This commit is contained in:
Vendored
+30
@@ -0,0 +1,30 @@
|
||||
// Type definitions for p-settle 2.0
|
||||
// Project: https://github.com/sindresorhus/p-settle#readme
|
||||
// Definitions by: Nate Silva <https://github.com/natesilva>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
declare namespace pSettle {
|
||||
interface SettledResult<T> {
|
||||
isFulfilled: boolean;
|
||||
isRejected: boolean;
|
||||
/** If the promise was fulfilled, the resolved value */
|
||||
value?: T;
|
||||
/** If the promise was rejected, the reason */
|
||||
reason?: any;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a Promise that is fulfilled when all promises in `input` are settled.
|
||||
*
|
||||
* The fulfilled value is an array of objects with the following properties:
|
||||
*
|
||||
* * `isFulfilled`
|
||||
* * `isRejected`
|
||||
* * `value` or `reason` (Depending on whether the promise fulfilled or rejected)
|
||||
*
|
||||
* @param input
|
||||
*/
|
||||
declare function pSettle<T>(input: Iterable<PromiseLike<T>>): Promise<Array<pSettle.SettledResult<T>>>;
|
||||
|
||||
export = pSettle;
|
||||
@@ -0,0 +1,13 @@
|
||||
import pSettle = require('p-settle');
|
||||
|
||||
async function f() {
|
||||
const promises: Array<Promise<string>> = [];
|
||||
for (let index = 0; index < 10; ++index) {
|
||||
if (index % 3 === 0) {
|
||||
promises.push(Promise.reject(new Error('i reject you')));
|
||||
} else {
|
||||
promises.push(Promise.resolve('🦄'));
|
||||
}
|
||||
}
|
||||
const results = await pSettle(promises);
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "es6",
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"p-settle-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user