You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This a bare bones [Promises/A+](http://promises-aplus.github.com/promises-spec/) implementation.
4
+
This is a simple implementation of Promises. It is a super set of ES6 Promises designed to have readable, performant code and to provide just the extensions that are absolutely necessary for using promises today.
5
5
6
-
It is designed to get the basics spot on correct, so that you can build extended promise implementations on top of it.
6
+
For detailed tutorials on its use, see www.promisejs.org
The example below shows how you can load the promise library (in a way that works on both client and server). It then demonstrates creating a promise from scratch. You simply call `new Promise(fn)`. There is a complete specification for what is returned by this method in [Promises/A+](http://promises-aplus.github.com/promises-spec/).
28
+
The example below shows how you can load the promise library (in a way that works on both client and server). It then demonstrates creating a promise from scratch. You simply call `new Promise(fn)`. There is a complete specification for what is returned by this method in [Promises/A+](http://promises-aplus.github.com/promises-spec/).
29
29
30
30
```javascript
31
31
varPromise=require('promise');
@@ -57,11 +57,13 @@ This creates and returns a new promise. `resolver` must be a function. The `re
57
57
58
58
These methods are invoked by calling `Promise.methodName`.
Converts values and foreign promises into Promises/A+ promises. If you pass it a value then it returns a Promise for that value. If you pass it something that is close to a promise (such as a jQuery attempt at a promise) it returns a Promise that takes on the state of `value` (rejected or fulfilled).
Returns a promise for an array. If it is called with a single argument that `Array.isArray` then this returns a promise for a copy of that array with any promises replaced by their fulfilled values. Otherwise it returns a promise for an array that conatins its arguments, except with promises replaced by their resolution values. e.g.
Takes a function which accepts a node style callback and returns a new function that returns a promise instead.
87
91
88
92
e.g.
@@ -101,6 +105,8 @@ var p = read('foo.json', 'utf8')
101
105
102
106
#### Promise.nodeify(fn)
103
107
108
+
_Non Standard_
109
+
104
110
The twin to `denodeify` is useful when you want to export an API that can be used by people who haven't learnt about the brilliance of promises yet.
105
111
106
112
```javascript
@@ -128,10 +134,14 @@ The call to `.then` also returns a promise. If the handler that is called retur
128
134
129
135
#### Promise#done(onFulfilled, onRejected)
130
136
137
+
_Non Standard_
138
+
131
139
The same semantics as `.then` except that it does not return a promise and any exceptions are re-thrown so that they can be logged (crashing the application in non-browser environments)
132
140
133
141
#### Promise#nodeify(callback)
134
142
143
+
_Non Standard_
144
+
135
145
If `callback` is `null` or `undefined` it just returns `this`. If `callback` is a function it is called with rejection reason as the first argument and result as the second argument (as per the node.js convention).
0 commit comments