UNPKG

@johngw/stream

Version:

Reactive programming tools using the WHATWG Streams API.

36 lines 865 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.after = void 0; /** * Prevents chunks from travelling down the stream * until the predicate returns true. * * @group Transformers * @example * ``` * --0--1--2--3--4--5--6--1--2--3--4-- * * after(x => x > 4) * * ------------------5--6--1--2--3--4- * ``` */ function after(predicate) { let pass = false; return new TransformStream({ async transform(chunk, controller) { if (pass) return controller.enqueue(chunk); try { pass = await predicate(chunk); } catch (error) { return controller.error(error); } if (pass) controller.enqueue(chunk); }, }); } exports.after = after; //# sourceMappingURL=after.js.map