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
Let your library support any ES 2015 (ES6) compatible `Promise` and leave the choice to application authors. The application can register its preferred `Promise` implementation and it will be exported when requiring `any-promise` from library code.
5
+
Let your library support any ES 2015 (ES6) compatible `Promise` and leave the choice to application authors. The application can *optionally*register its preferred `Promise` implementation and it will be exported when requiring `any-promise` from library code.
6
6
7
7
If no preference is registered, defaults to the global `Promise` for newer Node.js versions. The browser version defaults to the window `Promise`, so polyfill or register as necessary.
8
8
9
-
#### Usage:
9
+
### Usage with global Promise:
10
+
11
+
Assuming the global `Promise` is the desired implementation:
12
+
13
+
```bash
14
+
# Install any libraries depending on any-promise
15
+
$ npm install mz
16
+
```
17
+
18
+
The installed libraries will use global Promise by default.
19
+
20
+
```js
21
+
// in library
22
+
varPromise=require('any-promise') // the global Promise
23
+
24
+
functionpromiseReturningFunction(){
25
+
returnnewPromise(function(resolve, reject){...})
26
+
}
27
+
```
28
+
29
+
### Usage with registration:
10
30
11
31
Assuming `bluebird` is the desired Promise implementation:
12
32
@@ -18,6 +38,7 @@ $ npm install any-promise
18
38
# Install any libraries you would like to use depending on any-promise
19
39
$ npm install mz
20
40
```
41
+
21
42
Register your preference in the application entry point before any other `require` of packages that load `any-promise`:
22
43
23
44
```javascript
@@ -38,7 +59,7 @@ var Promise = require('any-promise') // the registered bluebird promise
38
59
39
60
It is safe to call `register` multiple times, but it must always be with the same implementation.
40
61
41
-
Again, registration is *optional*. It should only be called by the application user if overriding the global `Promise`implemementation is desired.
62
+
Again, registration is *optional*. It should only be called by the application user if overriding the global `Promise`implementation is desired.
42
63
43
64
### Optional Application Registration
44
65
@@ -118,7 +139,7 @@ return new Promise(function(resolve, reject){
118
139
119
140
```
120
141
121
-
Libraries using `any-promise` should only use [documented](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) functions as there is no guarantee which implementation will be chosen by the application author. Libraries should never call `register`, only the application user should call if desired.
142
+
Except noted below, libraries using `any-promise` should only use [documented](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) functions as there is no guarantee which implementation will be chosen by the application author. Libraries should never call `register`, only the application user should call if desired.
0 commit comments