source: trip-planner-front/node_modules/p-defer/readme.md@ 1ad8e64

Last change on this file since 1ad8e64 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 988 bytes
Line 
1# p-defer [![Build Status](https://travis-ci.org/sindresorhus/p-defer.svg?branch=master)](https://travis-ci.org/sindresorhus/p-defer)
2
3> Create a deferred promise
4
5[**Don't use this unless you know what you're doing!**](https://github.com/petkaantonov/bluebird/wiki/Promise-anti-patterns#the-deferred-anti-pattern) Prefer the `Promise` constructor.
6
7
8## Install
9
10```
11$ npm install --save p-defer
12```
13
14
15## Usage
16
17```js
18const pDefer = require('p-defer');
19
20function delay(ms) {
21 const deferred = pDefer();
22 setTimeout(deferred.resolve, ms, '🦄');
23 return deferred.promise;
24}
25
26delay(100).then(console.log);
27//=> '🦄'
28```
29
30*The above is just an example. Use [`delay`](https://github.com/sindresorhus/delay) if you need to delay a promise.*
31
32
33## API
34
35### pDefer()
36
37Returns an `Object` with a `promise` property and functions to `resolve()` and `reject()`.
38
39
40## Related
41
42- [More…](https://github.com/sindresorhus/promise-fun)
43
44
45## License
46
47MIT © [Sindre Sorhus](https://sindresorhus.com)
Note: See TracBrowser for help on using the repository browser.