# pub-sub-then

> A publisher subscriber library

Latest version **0.1.5** (published 2014-06-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install pub-sub-then
pnpm add pub-sub-then
yarn add pub-sub-then
bun add pub-sub-then
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.5 |
| Published | 2014-06-30 |
| First published | 2014-05-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Davide Fiorello |
| Maintainers | davidefiorello |
| Keywords | pub sub, publish, subscribe, observer, mediator, events, decoupling |

## Links

- npm: https://www.npmjs.com/package/pub-sub-then
- Repository: https://github.com/codeflyer/pubsubthen
- Issues: https://github.com/codeflyer/pubsubthen/issues
- npm.io page: https://npm.io/package/pub-sub-then

## Dependencies (2)

- [q](https://npm.io/package/q.md) ^1.0.1
- [async](https://npm.io/package/async.md) ^0.9.0

## Alternatives

- [async-exit-hook](https://npm.io/package/async-exit-hook.md) — 3.7M weekly downloads
- [evnty](https://npm.io/package/evnty.md) — 7.2K weekly downloads
- [eleventy-plugin-asciidoc](https://npm.io/package/eleventy-plugin-asciidoc.md) — 3.5K weekly downloads
- [@jswork/next-get2get](https://npm.io/package/@jswork/next-get2get.md) — 945 weekly downloads
- [@dashersw/axon](https://npm.io/package/@dashersw/axon.md) — 934 weekly downloads

## Recent versions

- 0.1.5 (latest) — 2014-06-30
- 0.1.4 — 2014-05-21
- 0.1.3 — 2014-05-20
- 0.1.2 — 2014-05-17
- 0.1.1 — 2014-05-17

## README

# PubSubThen


[![Build Status](https://drone.io/github.com/codeflyer/pubsubthen/status.png)](https://drone.io/github.com/codeflyer/pubsubthen/latest)
[![GitHub version](https://badge.fury.io/gh/codeflyer%2Fpubsubthen.svg)](http://badge.fury.io/gh/codeflyer%2Fpubsubthen)

PubSubThen is a synchronous [publish/subscribe](http://en.wikipedia.org/wiki/Publish/subscribe) node.js module.

PubSubThen was developed for the purpose of complete separation of modules in node.js.

PubSubThen supports a synchronous topic publication.


## Getting PubSubThen

There are several ways of getting PubSubThen

* [Download a tagged version](https://github.com/codeflyer/pubsubthen/tags) from GitHub
* Install via npm (`npm install pub-sub-then`)

## Examples

### Basic example

```javascript
// Require
var PubSubThen = require('../lib/PubSubThen');

// Add a subscription to topic
PubSubThen.subscribe('my-message', function(arg1, arg2, next) {
    // Do something with arg1
    arg1.push('new value');
    // Do something with arg2
    arg2.push('new value 2');
    
    next();
});

// Publish the topic
var list1 = [];
var list2 = [];
PubSubThen.publish('my-message', list1, list2).then(
    function() {
        try {
            console.log(list1);
            console.log(list2);
        } catch(e) {
        }
    },
    function(err) {
        throw err;
    }
);
```

### Unsubscribe

```javascript
// Add a subscription to topic
var subscription = PubSubThen.subscribe('my-message', function(args, next) {
    // Do something 
    
    next();
});

PubSubThen.unsubscribe('my-message', subscription);
```

### Cancel all subscriptions for a message

```javascript
// Add a subscription to topic
PubSubThen.subscribe('my-message', function(args, next) {
    // FUNC 1
    next();
});

PubSubThen.subscribe('my-message', function(args, next) {
    // FUNC 2
    next();
});

PubSubThen.removeAllSubscription('my-message');
```


## More about Publish/Subscribe

* [The Many Faces of Publish/Subscribe](http://www.cs.ru.nl/~pieter/oss/manyfaces.pdf) (PDF)
* [Addy Osmani's mini book on Patterns](http://addyosmani.com/resources/essentialjsdesignpatterns/book/#observerpatternjavascript)
* [Publish / Subscribe Systems, A summary of 'The Many Faces of Publish / Subscribe'](http://downloads.ohohlfeld.com/talks/hohlfeld_schroeder-publish_subscribe_systems-dsmware_eurecom2007.pdf)

## License

MIT: http://codeflyer.mit-license.org/

---
_Source: https://npm.io/package/pub-sub-then · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
