web-streams-extensions
Version:
A comprehensive collection of helper methods for WebStreams with built-in backpressure support, inspired by ReactiveExtensions
27 lines (26 loc) • 749 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.empty = empty;
/**
* Creates a ReadableStream that immediately completes without emitting any values.
* Useful for conditional logic and as a base case in stream operations.
*
* @template T The type of values the stream would emit (never actually emitted)
* @returns A ReadableStream that completes immediately
*
* @example
* ```typescript
* // Use in conditional logic
* const stream = condition ? from([1, 2, 3]) : empty();
*
* // Always completes immediately
* const result = await toArray(empty()); // []
* ```
*/
function empty() {
return new ReadableStream({
start(controller) {
controller.close();
}
});
}