Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cawfree/timebuffer
⏲️ Simple segmentation of timeboxed data handlers.
https://github.com/cawfree/timebuffer
buffer event listener message split timed
Last synced: 3 days ago
JSON representation
⏲️ Simple segmentation of timeboxed data handlers.
- Host: GitHub
- URL: https://github.com/cawfree/timebuffer
- Owner: cawfree
- License: mit
- Created: 2020-03-22T23:17:01.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-01-05T16:49:32.000Z (almost 2 years ago)
- Last Synced: 2024-05-01T14:49:34.283Z (6 months ago)
- Topics: buffer, event, listener, message, split, timed
- Language: JavaScript
- Homepage:
- Size: 1.26 MB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 14
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# timebuffer
Simple segmentation of timeboxed data handlers. Easily distribute periodic messages to dedicated handlers.## 🚀 Getting Started
Using [`npm`]():
```sh
npm i -s @cawfree/timebuffer
```Using [`yarn`]():
```sh
yarn add @cawfree/timebuffer
```## ✍️ Usage
Through calls to `use()`, we can define multiple timeboxed handlers; these declare which channels of data they're sensitive to, and will receive an aggregate collection of this data via the specified callback. In addition, they will receive the data supplied from the previous execution frame, to aid comparison between periods of data.
Each declared channel of sensitivity will be returned by the `TimeBuffer` instance, which will manage segmentation and garbage collection.
```javascript
import TimeBuffer from "@cawfree/timebuffer";const { population, currency } = new TimeBuffer()
// XXX: Process all currency values in 1000ms intervals.
.use(['currency'], 1000, (nextProps, lastProps) => {
const { currency: nextCurrency } = nextProps;
const { currency: lastCurrency } = lastProps;
})
// XXX: Process all currency and population values in 2000ms intervals.
.use(['currency', 'population'], 2000, (nextProps, lastProps) => {
const { population: nextPopulation } = nextProps;
const { currency: lastCurrency } = lastProps;
});// XXX: Post values of population and currency.
population(5000);
currency(200);
currency(250);await new Promise(resolve => setTimeout(resolve, 10000));
population(2500);
currency(44);
```## ✌️ License
[MIT](https://opensource.org/licenses/MIT)