mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-11 12:30:18 +00:00
Initial version.
This commit is contained in:
Vendored
+20
@@ -0,0 +1,20 @@
|
||||
// Type definitions for promise-dag 1.0
|
||||
// Project: https://github.com/vvvvalvalval/promise-dag#readme
|
||||
// Definitions by: Sjoerd Diepen <https://github.com/OSjoerdWie>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
export type Step = string | ((...args: any[]) => PromiseLike<any>);
|
||||
|
||||
export interface Run {
|
||||
(steps: { [name: string]: Step[]; }, required?: string[]): { [name: string]: Promise<any>; };
|
||||
}
|
||||
|
||||
export interface PromiseImplementation {
|
||||
resolve<T>(value: T): PromiseLike<T>;
|
||||
reject<T>(value: T): PromiseLike<T>;
|
||||
all<T>(values: (T | PromiseLike<T>)[]): PromiseLike<T[]>;
|
||||
}
|
||||
|
||||
export const run: Run;
|
||||
|
||||
export function implement(implementation: PromiseImplementation): Run;
|
||||
@@ -0,0 +1,35 @@
|
||||
import * as promiseDag from "promise-dag";
|
||||
|
||||
// describe the computation as steps which depend on previous steps.
|
||||
// in this cooking example, functions which return a promise are prefixed with `p_`.
|
||||
const mushroomPastaRecipe = {
|
||||
hotWater: [(): Promise<string> => p_boilWater("1L")],
|
||||
rawPasta: [(): Promise<string> => p_pickIngredient("pasta")],
|
||||
cookedPasta: ["hotWater", "rawPasta", (hotWater: string, rawPasta: string) => p_boil(hotWater, rawPasta, "10 minutes")],
|
||||
|
||||
meal: ["cookedPasta", (preparedMeal: string): Promise<string> => Promise.resolve(preparedMeal)]
|
||||
};
|
||||
|
||||
const runCustomPromise = promiseDag.implement({
|
||||
resolve: (v: any): Promise<any> => Promise.resolve(v),
|
||||
reject: (err: any): Promise<any> => Promise.resolve(err),
|
||||
all: (ps: (any | PromiseLike<any>)[]): Promise<any[]> => Promise.all(ps)
|
||||
});
|
||||
|
||||
runCustomPromise(mushroomPastaRecipe, ["meal"]).meal.then(eat);
|
||||
|
||||
function eat(meal: string) {
|
||||
let consume = `eating ${meal}`;
|
||||
}
|
||||
|
||||
function p_boilWater(volume: string): Promise<string> {
|
||||
return Promise.resolve(volume);
|
||||
}
|
||||
|
||||
function p_pickIngredient(ingredient: string): Promise<string> {
|
||||
return Promise.resolve(ingredient);
|
||||
}
|
||||
|
||||
function p_boil(volume: string, ingredient: string, duration: string): Promise<string> {
|
||||
return Promise.resolve(`cooked ${ingredient} in ${volume} for ${duration}`);
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"promise-dag-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user