Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/smelukov/promisedelay
Simple delay promise
https://github.com/smelukov/promisedelay
Last synced: about 1 month ago
JSON representation
Simple delay promise
- Host: GitHub
- URL: https://github.com/smelukov/promisedelay
- Owner: smelukov
- License: mit
- Created: 2016-01-24T14:33:03.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2016-01-25T22:51:10.000Z (almost 9 years ago)
- Last Synced: 2024-10-09T13:48:50.285Z (about 1 month ago)
- Language: JavaScript
- Size: 8.79 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
[![Build Status](https://travis-ci.org/smelukov/PromiseDelay.svg?branch=master)](https://travis-ci.org/smelukov/PromiseDelay)
# PromiseDelay
Simple delay promise.### Usage
```javascript
require('promise-ext-delay')();Promise.delay(1000).then(function(){...})
```### Description
This is realization of a small and simple delay promise, that supports CommonJS, AMD ang non-module definition.The module is function, that extends any promise constructor and first of all, you'll need to call this function to extend promise constructor.
Injection for CommonJS:
```javascript
require('promise-ext-delay')();
```Injection for AMD:
```javascript
require(['promiseDelay'], function(PromiseDelay){
PromiseDelay();
});
```Injection for non-module environment:
```htmlPromiseDelay(); //in non-module environment, global function PromiseDelay will be created
```
The function that injects delay promise have 2 parameters:
- `PromiseConstructor` - just function-constructor, that will be extended. If nothing is passed, then default promise constructor will be used.
- `extName` - name of the delay function/method. If nothing is passed, then `delay` will be used. Can be passed instead of the first parameter.Some examples of injection:
```javascript
PromiseDelay(); //or
PromiseDelay(YourCustomPromiseConstructor, 'methodName'); //or
PromiseDelay('methodName');
```After injection, you'll may use delay promise:
**As static function**
```javascript
Promise.delay(1000).then(function(){...})
```
**Or as object method**
```javascript
var p = new Prmise(function(resolve){
resolve('some value');
});p.delay(5000).then(function(){...});
```Notice that delay promise will pass promise value through itself, therefore you'll receive your value in promise chain after delay promise.