Projekt

Obecné

Profil

Stáhnout (2.63 KB) Statistiky
| Větev: | Revize:
1 3a515b92 cagy
<h1 align="center">
2
	<br>
3
	<img width="256" src="media/logo.png" alt="pinkie">
4
	<br>
5
	<br>
6
</h1>
7
8
> Itty bitty little widdle twinkie pinkie [ES2015 Promise](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-promise-objects) implementation
9
10
[![Build Status](https://travis-ci.org/floatdrop/pinkie.svg?branch=master)](https://travis-ci.org/floatdrop/pinkie)  [![Coverage Status](https://coveralls.io/repos/floatdrop/pinkie/badge.svg?branch=master&service=github)](https://coveralls.io/github/floatdrop/pinkie?branch=master)
11
12
There are [tons of Promise implementations](https://github.com/promises-aplus/promises-spec/blob/master/implementations.md#standalone) out there, but all of them focus on browser compatibility and are often bloated with functionality.
13
14
This module is an exact Promise specification polyfill (like [native-promise-only](https://github.com/getify/native-promise-only)), but in Node.js land (it should be browserify-able though).
15
16
17
## Install
18
19
```
20
$ npm install --save pinkie
21
```
22
23
24
## Usage
25
26
```js
27
var fs = require('fs');
28
var Promise = require('pinkie');
29
30
new Promise(function (resolve, reject) {
31
	fs.readFile('foo.json', 'utf8', function (err, data) {
32
		if (err) {
33
			reject(err);
34
			return;
35
		}
36
37
		resolve(data);
38
	});
39
});
40
//=> Promise
41
```
42
43
44
### API
45
46
`pinkie` exports bare [ES2015 Promise](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-promise-objects) implementation and polyfills [Node.js rejection events](https://nodejs.org/api/process.html#process_event_unhandledrejection). In case you forgot:
47
48
#### new Promise(executor)
49
50
Returns new instance of `Promise`.
51
52
##### executor
53
54
*Required*  
55
Type: `function`
56
57
Function with two arguments `resolve` and `reject`. The first argument fulfills the promise, the second argument rejects it.
58
59
#### pinkie.all(promises)
60
61
Returns a promise that resolves when all of the promises in the `promises` Array argument have resolved.
62
63
#### pinkie.race(promises)
64
65
Returns a promise that resolves or rejects as soon as one of the promises in the `promises` Array resolves or rejects, with the value or reason from that promise.
66
67
#### pinkie.reject(reason)
68
69
Returns a Promise object that is rejected with the given `reason`.
70
71
#### pinkie.resolve(value)
72
73
Returns a Promise object that is resolved with the given `value`. If the `value` is a thenable (i.e. has a then method), the returned promise will "follow" that thenable, adopting its eventual state; otherwise the returned promise will be fulfilled with the `value`.
74
75
76
## Related
77
78
- [pinkie-promise](https://github.com/floatdrop/pinkie-promise) - Returns the native Promise or this module
79
80
81
## License
82
83
MIT © [Vsevolod Strukchinsky](http://github.com/floatdrop)