https://github.com/carloslfu/pullable-event-bus
An event bus where emitters can pull data from subscribers
https://github.com/carloslfu/pullable-event-bus
event-bus events javascript pullable pullable-event-bus typescript
Last synced: about 2 months ago
JSON representation
An event bus where emitters can pull data from subscribers
- Host: GitHub
- URL: https://github.com/carloslfu/pullable-event-bus
- Owner: carloslfu
- License: mit
- Created: 2018-02-25T06:44:44.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-04-25T03:54:01.000Z (about 8 years ago)
- Last Synced: 2025-10-06T19:37:15.619Z (8 months ago)
- Topics: event-bus, events, javascript, pullable, pullable-event-bus, typescript
- Language: TypeScript
- Homepage:
- Size: 37.1 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Pullable Event Bus
A minimal event bus where emmiters can pull data from subscribers
1. Install it with: `npm i --save pullable-event-bus` or `yarn add pullable-event-bus`
2. Import it:
```javascript
// ES6
import { makeEventBus } from 'pullable-event-bus'
// Node.js
const { makeEventBus } = require('pullable-event-bus')
```
3. Use it:
```javascript
const eventBus = makeEventBus()
// subscribers
eventBus.on('channel', data => console.log(data))
eventBus.on('channel', data => data + 1, true) // true means is a pullable subscriber
// emit a message
eventBus.emit('channel', 10).then(results => console.log(results))
// logs:
// 10 from first subscriber
// [11] as the result of emitting the message and the '11' comes from the second (the pullable) subscriber
```
Have fun!