# causeeffect

> Evented rules for nodejs - flow management simplified

Latest version **0.1.4** (published 2012-06-26) · 0 weekly downloads

## Install

```sh
npm install causeeffect
pnpm add causeeffect
yarn add causeeffect
bun add causeeffect
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.4 |
| Published | 2012-06-26 |
| First published | 2011-02-07 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 31 |
| Author | Laura Doktorova |
| Maintainers | olado |
| Keywords | event, events, simple, flow, parallel, util, utility |

## Links

- npm: https://www.npmjs.com/package/causeeffect
- Repository: https://github.com/olado/causeeffect
- Homepage: http://github.com/olado/causeeffect
- npm.io page: https://npm.io/package/causeeffect

## 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.4 (latest) — 2012-06-26
- 0.1.3 — 2011-03-04
- 0.1.2 — 2011-02-27
- 0.1.1 — 2011-02-10
- 0.1.0 — 2011-02-07

## README

Created to simplify flow management when programming in asynchronous
environments like nodejs.

	CauseEffect extends EventEmitter and allows to set cause-effect scenarios.

	It is simple yet effective.

	CauseEffect allows you to:
	* have an event fired when multiple parallel flows complete.
	* easily unite multiple parallel flows initiated from the for loop.
	* set up chains: completion of one rule may trigger another.
	* set the rules dynamically or statically.
	* have an event fired when any of the flows completes.

	To run example:
		node examples/sample.js

Installation:
	npm install causeeffect

Usage:
	To setup a rule where an event will fire if all of the causes happen:
		ce.setEvents("myevent", ["cause1", "cause2", "cause3"]);

	To setup a rule where an event will fire if some of the causes happen:
		ce.setEvents("myevent", ["cause1", "cause2", "cause3"], true);

	To setup a rule where an event will fire if it happens X times:
		ce.setEvents("myevent", 10);

	Listen to effect event as usual with EventEmitter API:
		ce.on("myevent", callback);

	To let CauseEffect know that the cause has happened call:
		ce.setState("cause1");
	or if you need a specific value use
		ce.setState("cause1", value);
	This value can be then obtained from your event callback with:
		ce.getState("cause1")

	To run example:
		node examples/sample.js

Sample:

1. Uniting multiple parallel flows initiated from the for loop:
	var ce = require('causeeffect');
	ce = new ce.CauseEffect();

	// Set up ticker cause. Event "myticker" will fire if ce.setState("myticker") was invoked 4 times.
	// Handy for figuring out when all callbacks have been called initiated from the for loop.
	ce.setEvents("myticker", 4);

	function callback() {
		ce.setState("myticker");
	}

	for(var i = 0; i< 4; i++) {
		setTimeout(callback, 100);
	}

	ce.on("myticker", function() {
	});


2. Uniting specific parallel flows
	// Set up AND cause effect. Event "alldone" will be fired if all of causes happen
	ce.setEvents("alldone", ["cause1", "cause2", "myticker"]);

	// Listen to event as usual with EventEmitter API
	ce.on("alldone", function() {
	});


	// To let CauseEffect know that the cause has happened 
	ce.setState("cause1");
	ce.setState("cause2");

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