https://github.com/jabr/what-bus
An event-bus based on the WHATWG's BroadcastChannel API
https://github.com/jabr/what-bus
Last synced: 3 months ago
JSON representation
An event-bus based on the WHATWG's BroadcastChannel API
- Host: GitHub
- URL: https://github.com/jabr/what-bus
- Owner: jabr
- License: mit
- Created: 2021-07-21T05:32:34.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2022-01-17T04:53:28.000Z (over 3 years ago)
- Last Synced: 2025-03-15T00:11:16.656Z (3 months ago)
- Language: TypeScript
- Size: 28.3 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# what-bus
An event-bus based on the WHATWG's BroadcastChannel API.
The `core` module is a basic framework for creating, caching and clean-up of the underlying channel instances.
The `cluster` module is currently a work-in-progress, with the goal of coordination in a cluster of distributed WhatBus instances. Some implemented, partially complete, and planned features:
* [Rendezvous hashing](https://en.wikipedia.org/wiki/Rendezvous_hashing#Algorithm)
* [Raft consensus](https://en.wikipedia.org/wiki/Raft_(algorithm))
* distributed Maps, Sets, executors
* data replication & failover
* distributed queues, transactions## Example
```js
import WhatBus from "./core.ts"
const wb = new WhatBus('wb:')let s1 = wb.subscribe('t:1', event => console.log('s1', event.data))
wb.subscribeOnce('t:1', /* ... */)wb.publish('t:1', { m: 100 })
wb.close()import { create } from "./cluster.ts"
const wb = await create('twb:')
// @todo: cluster examples
```## References
* BroadcastChannel
- [WHATWG Spec](https://html.spec.whatwg.org/multipage/web-messaging.html#broadcasting-to-other-browsing-contexts)
- [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/BroadcastChannel)
- [Deno Deploy](https://deno.com/deploy/docs/runtime-broadcast-channel)## License
This project is licensed under the terms of the [MIT license](LICENSE.txt).