https://github.com/scalajs-io/stream-throttle
A rate limiter for Node.js streams.
https://github.com/scalajs-io/stream-throttle
node node-js nodejs npm npm-package scala scalajs stream throttle throttling
Last synced: 4 months ago
JSON representation
A rate limiter for Node.js streams.
- Host: GitHub
- URL: https://github.com/scalajs-io/stream-throttle
- Owner: scalajs-io
- Created: 2017-02-21T20:44:31.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2019-06-17T23:11:23.000Z (about 6 years ago)
- Last Synced: 2025-01-17T22:42:27.059Z (5 months ago)
- Topics: node, node-js, nodejs, npm, npm-package, scala, scalajs, stream, throttle, throttling
- Language: Scala
- Size: 9.77 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
stream-throttle package for Scala.js
================================
[stream-throttle](https://www.npmjs.com/package/stream-throttle) - A rate limiter for Node.js streams.### Description
A rate limiter for Node.js streams.
* [SBT v1.2.x](http://www.scala-sbt.org/download.html)
### Build/publish the SDK locally```bash
$ sbt clean publish-local
```### Running the tests
Before running the tests the first time, you must ensure the npm packages are installed:
```bash
$ npm install
```Then you can run the tests:
```bash
$ sbt test
```### Examples
```scala
import io.scalajs.nodejs._
import io.scalajs.npm.streamthrottle._process.stdin.pipe(new Throttle(new ThrottleOptions(rate = 10))).pipe(process.stdout)
``````scala
import io.scalajs.nodejs._
import io.scalajs.nodejs.net._
import io.scalajs.npm.streamthrottle._
import scalajs.jsval tg = new ThrottleGroup(new ThrottleOptions(rate = 10240))
val conn1 = Net.createConnection(host = "www.google.com", port = 80)
val conn2 = Net.createConnection(host = "www.google.com", port = 80)val thr1 = conn1.pipe(tg.throttle())
val thr2 = conn2.pipe(tg.throttle())// Reads from thr1 and thr2 are throttled to 10 KB/s in aggregate
```### Artifacts and Resolvers
To add the `stream-throttle` binding to your project, add the following to your build.sbt:
```sbt
libraryDependencies += "io.scalajs.npm" %%% "stream-throttle" % "0.5.0"
```Optionally, you may add the Sonatype Repository resolver:
```sbt
resolvers += Resolver.sonatypeRepo("releases")
```