https://github.com/morulus/promisefactory
Custom Promise factory
https://github.com/morulus/promisefactory
Last synced: 11 months ago
JSON representation
Custom Promise factory
- Host: GitHub
- URL: https://github.com/morulus/promisefactory
- Owner: morulus
- Created: 2016-07-04T13:57:29.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2016-11-17T12:33:38.000Z (over 9 years ago)
- Last Synced: 2025-06-10T09:41:16.127Z (about 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 36.1 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
promiseFactory
--
An factory-function that can create custom Promise with your own configuration
# Getting started
## Install
ES6
```
import promiseFactory from 'promiseFactory';
```
ES5 compatible (excludes es6 features)
```js
var promiseFactory = require('promiseFactory/es5');
```
## Configurate
```js
var MyPromise = promiseFactory({
immediate: false,
perpetual: false,
autorun: true,
external: false,
chaining: true,
});
```
### Params
- immediate (default: FALSE) If TRUE `then`|`catch` handler executes right after calling `resolve`, if FALSE `then`|`catch` handler invokes at next tick
- perpetual (default: FALSE) If TRUE The Promise will never be completed. You can call `resolve` again and again.
- autorun (default: TRUE) If FALSE function `resolver` will not executed automaticly, you have to call `execute` method manually.
- external: (default: FALSE) If TRUE allows to call methods `resolve` and `reject` from outside of Promise.
- chaining: (default: TRUE) If FALSE disables promise chaining, so `then` always returns origin Promise ref.
## Usage
Create your own Promise in a bundle of your project to use special abilities
```
global.StreamedPromise = promiseFactory({
perpetual: true,
autorun: false,
external: true
});
// Click counter example
var clicks = 0;
var clickCounter = StreamedPromise;
clickCounter
.then(function() {
++clicks;
console.log('You clicks ', clicks, 'times');
});
$("button").click(StreamedPromise.resolve.bind(StreamedPromise));
```
# License
MIT
# Author
Vladimir Kalmykov