GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Stream this.push and spread operator does not work · Issue #26582 · nodejs/node Closed Description
Hello, I have written a simple Transform stream to getting some extended user info: import { Transform } from 'stream'; import { getUsersPublicInfo } from '../../user/services'; const USERS_BATCH_SIZE = 100; /** * Class (extended from Transform stream) * for getting minimum user info for diff * types of reports. Returns `id`, `email` * and `name` in a stream as an object. */ export class FillUserTransform extends Transform { constructor(options) { super({ readableObjectMode: true, writableObjectMode: true, ...(options || {}), }); this._userIds = []; } /** * @param {{user_id: string}} chunk * @param {string} encoding * @param {Function} cb * @return {*} * @private */ _transform(chunk, encoding, cb) { this._userIds.push(chunk.user_id); if (this._userIds.length >= USERS_BATCH_SIZE) { this._writeUserInfo(cb); } else { return void cb(); } } _flush(cb) { if (this._userIds.length > 0) { this._writeUserInfo(cb); } else { return void cb(); } } /** * @param {Function} cb * @return {*} * @private */ _writeUserInfo(cb) { this.pause(); getUsersPublicInfo(this._userIds) .then(users => { if (users.length > 0) { this.push(...users); } this._userIds.length = 0; this.resume(); cb(); }) .catch(err => { this._userIds.length = 0; this.resume(); cb(err); }); } } but users.forEach(user => { this.push(user); }); Activity
|
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |