typed-promisify
Typescript promisify, map, and try
Last updated 4 years ago by notenoughneon .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install typed-promisify 
SYNC missed versions from official npm registry.

typed-promisify

Typescript promise helpers: promisify(), map(), and _try(). You will need ES6 promises. These helpers preserve types in the promises, enabling better typechecking and VS Code intellisense:

intellisense screenshot

API

import * as tp from 'typed-promisify';

promisify(fn)

Convert a node style callback function to one returning a promise.

Example:

var stat = tp.promisify(fs.stat);

stat('test.txt')
    .then(stats => console.log(stats));

map(elts, fn)

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:

var stat = tp.promisify(fs.stat);
var elts = ['test.txt', 'test2.txt'];

tp.map(elts, stat)
    .then(stats => console.log(stats));

_try(fn, arg1, arg2...)

Call a synchronous function to kick off a promise chain.

Example:

tp._try(fs.writeFileSync, 'test.txt', 'hello world')
    .then(() => {
        //do other stuff
    })
    .then(() => console.log('sucess'))
    .catch(err => console.log('failure'));

Current Tags

  • 0.4.0                                ...           latest (4 years ago)

4 Versions

  • 0.4.0                                ...           4 years ago
  • 0.3.0                                ...           4 years ago
  • 0.2.0                                ...           4 years ago
  • 0.1.0                                ...           4 years ago
Maintainers (1)
Downloads
Today 0
This Week 20
This Month 73
Last Day 3
Last Week 21
Last Month 255
Dependencies (0)
None
Dev Dependencies (3)

Copyright 2014 - 2016 © taobao.org |