1 | [![NPM Package](https://badge.fury.io/js/villa.svg)](https://www.npmjs.com/package/villa)
|
2 | [![Build Status](https://travis-ci.org/vilic/villa.svg)](https://travis-ci.org/vilic/villa)
|
3 | [![Coverage Status](https://coveralls.io/repos/github/vilic/villa/badge.svg?branch=master)](https://coveralls.io/github/vilic/villa?branch=master)
|
4 |
|
5 | # Villa
|
6 |
|
7 | Villa is a set of promise utilities for `async`-`await`-ready environment.
|
8 |
|
9 | Promises have been widely used in JavaScript, and there are quite a few fully
|
10 | featured promise libraries like
|
11 | [bluebird](https://github.com/petkaantonov/bluebird) and
|
12 | [Q](https://github.com/kriskowal/q). But with the growing adoption of
|
13 | `async`/`await` provided by ES-next (via transpilers like
|
14 | [TypeScript](http://www.typescriptlang.org/) and [Babel](http://babeljs.io/)),
|
15 | some cretical features provided by those libraries become less relevant.
|
16 |
|
17 | And there is another problem with third-party promise for code using
|
18 | `async`/`await`: it could be confusing having different promise instances with
|
19 | different APIs, while an `async` function always returns native promise object.
|
20 |
|
21 | While most of the promise use cases so far can be addressed using
|
22 | `async`/`await` with simple helpers, I created villa with my favorite features
|
23 | from my own promise library [ThenFail](https://github.com/vilic/thenfail).
|
24 |
|
25 | # Installation
|
26 |
|
27 | Villa is written in TypeScript and compiled with TypeScript 2.0, and works with
|
28 | both TypeScript and Babel.
|
29 |
|
30 | ```sh
|
31 | npm install villa --save
|
32 | ```
|
33 |
|
34 | # Example
|
35 |
|
36 | ```ts
|
37 | import * as FS from 'fs';
|
38 | import { awaitable } from 'villa';
|
39 |
|
40 | async function copy(source, target) {
|
41 | let readStream = FS.createReadStream(source);
|
42 | let writeStream = FS.createWriteStream(target);
|
43 | readStream.pipe(writeStream);
|
44 | return awaitable(writeStream, 'close', [readStream]);
|
45 | }
|
46 | ```
|
47 |
|
48 | # License
|
49 |
|
50 | MIT License.
|