Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lanfei/deferred-lib
A lightweight implementation of Deferred/Promise.
https://github.com/lanfei/deferred-lib
deffered promise
Last synced: 5 days ago
JSON representation
A lightweight implementation of Deferred/Promise.
- Host: GitHub
- URL: https://github.com/lanfei/deferred-lib
- Owner: Lanfei
- Created: 2014-08-20T10:35:00.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2016-07-19T08:23:20.000Z (over 8 years ago)
- Last Synced: 2024-12-16T19:57:06.555Z (about 2 months ago)
- Topics: deffered, promise
- Language: JavaScript
- Homepage: https://nodei.co/npm/deferred-lib
- Size: 15.6 KB
- Stars: 0
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Deferred
A lightweight implementation of Deferred/Promise.
[![NPM](https://nodei.co/npm/deferred-lib.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/deferred-lib)
## Installation
### Node
```bash
$ npm install deferred-lib
```### Browser
```html
```
## Usage
```js
// Usage 1
// Declare the deferred instance and use it.
function countdown1() {
var deferred = new Deferred();
var i = 5;
var timer = setInterval(function () {
deferred.notify(i);
if (i-- === 0) {
deferred.resolve('Hi');
clearInterval(timer);
}
}, 300);
return deferred.promise();
}countdown1().progress(function (step) {
console.log('countdown1', step);
}).done(function () {
console.log('countdown1 done');
});// Usage 2
// Use `Deferred(fn)` and get the deferred instance with `this` context.
function countdown2() {
var self = this;
var i = 5;
var timer = setInterval(function () {
self.notify(i);
if (i-- === 0) {
self.resolve('Hi');
clearInterval(timer);
}
}, 300);
}Deferred(countdown2).progress(function (step) {
console.log('countdown2', step);
}).done(function () {
console.log('countdown2 done');
});
```**See `examples` directory for more usages.**