https://github.com/bredele/async
Collection of asynchronous patterns for nodejs and your browser.
https://github.com/bredele/async
Last synced: over 1 year ago
JSON representation
Collection of asynchronous patterns for nodejs and your browser.
- Host: GitHub
- URL: https://github.com/bredele/async
- Owner: bredele
- Created: 2014-04-06T15:21:55.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2014-04-25T18:52:22.000Z (about 12 years ago)
- Last Synced: 2025-02-12T09:54:29.547Z (over 1 year ago)
- Homepage: http://bredele.github.io/async
- Size: 203 KB
- Stars: 6
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
async
====
A place to put together clean and simple asynchronous patterns for nodejs and your browser.
## Emitter
> observer
**[emitter](http://github.com/component/component)** is a module made by the team [component](http://github.com/component).
```js
var emitter = new Emitter();
emitter.on('changed', function() {
// do something on changed
});
emitter.emit('changed');
```
## Promises
> promise
**[promise](http://github.com/bredele/promise)** is a promise A+ [implementation](http://promises-aplus.github.io/promises-spec/).
```js
var promise = new Promise();
promise.then(function(value) {
});
promise.resolve('because');
```
## Mood
> finite state machine
**[mood](https://github.com/bredele/mood)** is a finite state machine based on [emitter](http://github.com/component/emitter). It allows you to define transitions from one state to an other.
```js
var states = new Mood('open');
// transition open to locked
states.add('open','lock', function() {
//do something
}, 'locked');
states.emit('lock');
```
## Queue
> asynchronous emitter
**[queue](http://github.com/bredele/emitter-queue)** is a plugin for [emitter](http://github.com/component/emitter) and **[datastore](http://github.com/bredele/datastore)** that allows to listen events even after they have been fired.
```js
var emitter = new Emitter();
Queue(emitter);
emitter.queue('changed');
emitter.on('changed', function() {
// do something on changed
});
```
## Door
> door pattern
**[door](https://github.com/bredele/doors)** is a design pattern I invented.
```js
var door = new Door('awesome');
door.lock('foo');
door.lock('bar');
door.on('open', function() {
// do something when every lock are unlocked
});
door.unlock('bar', 'foo');
```
A door has two states (opened and closed) and can switch from one to an other indefinitely. Doors is the opposite of a finite state machine, a transition is trigerred by one or several conditions (or locks). To be opened, a door needs to unlock all locks and one lock is enough to close the door.