/brake

throttle a stream with backpressure

Primary LanguageScalaApache License 2.0Apache-2.0

Brake API for Scala.js

brake - Throttle a stream with backpressure.

Description

Throttle a stream with backpressure.

Build Dependencies

Build/publish the SDK locally

 $ sbt clean publish-local

Running the tests

Before running the tests the first time, you must ensure the npm packages are installed:

$ npm install

Then you can run the tests:

$ sbt test

Examples

import io.scalajs.nodejs.buffer.Buffer
import io.scalajs.nodejs.process
import io.scalajs.npm.brake.Brake
import io.scalajs.npm.readablestream.Readable

val bulk = new Readable()
bulk._read = () => {}

('A' to 'F') foreach { ch =>
  bulk.push(Buffer.from(String.valueOf(ch)))
}
bulk.push(null)
bulk.pipe(Brake(10)).pipe(process.stdout)
Output:
ABCDEF

Artifacts and Resolvers

To add the Brake binding to your project, add the following to your build.sbt:

libraryDependencies += "io.scalajs.npm" %%% "brake" % "0.5.0"

Optionally, you may add the Sonatype Repository resolver:

resolvers += Resolver.sonatypeRepo("releases")