Typescript promisify, map, and try
npm install typed-promisify``typescript`
import * as tp from 'typed-promisify';
Convert a node style callback function to one returning a promise.
Example:
`typescript
var stat = tp.promisify(fs.stat);
stat('test.txt')
.then(stats => console.log(stats));
`
Promise aware map.
Elts can be a promise for an array, an array of promises, or a promise for an array of promises. Fn can be synchronous or return a promise.
Returns a promises that resolves when all applied promises resolve (similar to Promise.all).
Example:
`typescript
var stat = tp.promisify(fs.stat);
var elts = ['test.txt', 'test2.txt'];
tp.map(elts, stat)
.then(stats => console.log(stats));
`
Call a synchronous function to kick off a promise chain.
Example:
`typescript``
tp._try(fs.writeFileSync, 'test.txt', 'hello world')
.then(() => {
//do other stuff
})
.then(() => console.log('sucess'))
.catch(err => console.log('failure'));