@promistream/end-of-stream

0.1.2 • Public • Published

@promistream/end-of-stream

A simple custom error type for marking the end of a Promistream. You'd usually only need this module when you're implementing a source stream.

Example

An example of producing an EndOfStream marker, from the range-numbers module, which is a source stream that produces numbers within a range:

"use strict";

const simpleSource = require("@promistream/simple-source");
const EndOfStream = require("@promistream/end-of-stream");

module.exports = function rangeNumbers(start, end, step = 1) {
	let i = start;

	return simpleSource({
		onRequest: () => {
			if (i >= end) {
				throw new EndOfStream();
			} else {
				let number = i;
				i += step;
				return number;
			}
		}
	});
}

API

EndOfStream()

A custom Error constructor, that produces an 'end of stream' marker; that is, a special kind of error to signal that the end of the source stream has been reached, and no further values should be requested.

Takes no arguments.

Readme

Keywords

none

Package Sidebar

Install

npm i @promistream/end-of-stream

Weekly Downloads

0

Version

0.1.2

License

WTFPL OR CC0-1.0

Unpacked Size

3.84 kB

Total Files

4

Last publish

Collaborators

  • joepie91