Merge pull request #16680 from natesilva/p-settle

Added types for p-settle
This commit is contained in:
Daniel Rosenwasser
2017-05-22 14:54:20 -07:00
committed by GitHub
4 changed files with 67 additions and 0 deletions
+30
View File
@@ -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;
+13
View File
@@ -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);
}
+23
View File
@@ -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"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }