Skip to content

Commit 7f5a5bc

Browse files
committed
fixup: benchmrk
1 parent de8bb15 commit 7f5a5bc

File tree

3 files changed

+20
-20
lines changed

3 files changed

+20
-20
lines changed

benchmark/streams/transform-by.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,14 @@ function main({ n }) {
1616
s.resume();
1717

1818
bench.start();
19-
for (var k = 0; k < n; ++k) {
20-
s.write(String.fromCharCode(n % 64 + 64));
19+
20+
let k = 0;
21+
function run() {
22+
while (k++ < n && s.write(b));
23+
if (k >= n)
24+
s.end();
2125
}
22-
s.end(() => bench.end(n));
26+
s.on('drain', run);
27+
s.on('finish', () => bench.end(n));
28+
run();
2329
}

doc/api/stream.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1646,14 +1646,14 @@ Calling `Readable.from(string)` or `Readable.from(buffer)` will not have
16461646
the strings or buffers be iterated to match the other streams semantics
16471647
for performance reasons.
16481648

1649-
### stream.Transform.by(asyncGeneratorFunction[, options])
1649+
### stream.Transform.by(transform[, options])
16501650
<!-- YAML
16511651
added: REPLACEME
16521652
-->
16531653

1654-
* `asyncGeneratorFunction` {AsyncGeneratorFunction} A mapping function which
1655-
accepts a `source` async iterable which can be used to read incoming data, while
1656-
transformed data is pushed to the stream with the `yield` keyword.
1654+
* `transform` {AsyncGeneratorFunction} A mapping function which accepts a `source`
1655+
async iterable which can be used to read incoming data, while transformed data is
1656+
pushed to the stream with the `yield` keyword.
16571657
* `options` {Object} Options provided to `new stream.Transform([options])`.
16581658
By default, `Transform.by()` will set `options.objectMode` to `true`,
16591659
unless this is explicitly opted out by setting `options.objectMode` to `false`.

lib/_stream_transform.js

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -71,23 +71,12 @@ const {
7171

7272
module.exports = Transform;
7373
const {
74-
ERR_ARG_RETURN_VALUE_NOT_ASYNC_ITERABLE,
7574
ERR_METHOD_NOT_IMPLEMENTED,
7675
ERR_MULTIPLE_CALLBACK,
7776
ERR_TRANSFORM_ALREADY_TRANSFORMING,
7877
ERR_TRANSFORM_WITH_LENGTH_0
7978
} = require('internal/errors').codes;
8079
const Duplex = require('_stream_duplex');
81-
const Readable = require('_stream_readable');
82-
const AsyncIteratorPrototype = ObjectGetPrototypeOf(
83-
ObjectGetPrototypeOf(async function* () {}).prototype);
84-
85-
const kSourceIteratorPull = Symbol('kSourceIteratorPull');
86-
const kSourceIteratorResolve = Symbol('kSourceIteratorResolve');
87-
const kSourceIteratorChunk = Symbol('kSourceIteratorChunk');
88-
const kSourceIteratorStream = Symbol('kSourceIteratorStream');
89-
const kSourceIteratorPump = Symbol('kSourceIteratorPump');
90-
const kSourceIteratorGrabResolve = Symbol('kSourceIteratorGrabResolve');
9180

9281
ObjectSetPrototypeOf(Transform.prototype, Duplex.prototype);
9382
ObjectSetPrototypeOf(Transform, Duplex);
@@ -235,10 +224,15 @@ function done(stream, er, data) {
235224

236225
const from = require('internal/streams/from');
237226

238-
Transform.by = function by(asyncGeneratorFn, opts) {
227+
Transform.by = function by(transform, opts) {
239228
let _resolve;
240229
let _promise = new Promise((resolve) => _resolve = resolve);
241-
return from(Duplex, asyncGeneratorFn(async function*() {
230+
231+
if (typeof transform !== 'function') {
232+
throw new ERR_INVALID_ARG_TYPE('transform', ['function'], iterable);
233+
}
234+
235+
return from(Duplex, transform(async function*() {
242236
while (true) {
243237
const { chunk, done, cb } = await _promise;
244238
if (done) return cb();

0 commit comments

Comments
 (0)