PromiseCascade
Easy to use library for cascading promises. If you're looking for a way to use the response from one promise into another, this library is meant for you.
Designed while working on the Premiere Library, PromiseCascade thrives helping keep concerns separate in a clean manner.
Installation
npm install promise-cascade --save
API
stack
: Stores pushed functions and argumentspush(fn: PromiseFunction, ...args: any[]): this
: Pushes a function to the stack (this function must return aPromise
)play(): Promise<any>
: Calls the pushed function with given args + callbackclear()
: Removes all values from thestack
Example
This examples are written in TypeScript. To use with ES6, just remove typings.
Pushing and Playing
; ; ; ; .pushaddAwesomeness .pushgetName, 'John Doe' .play; promise.then;
Real World Example - Extending PromiseCascade
This is a simplified version of Premiere's StoreCacheCascade
class.
;;; ; ; get1;
Resources
For more about how Promise works, check out Dave Atchley's article