xref: /third_party/node/test/parallel/test-stream-readable-hwm-0-async.js
  • Home
  • History
  • Annotate Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
  • only in /third_party/node/test/parallel/
11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ciconst common = require('../common');
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ci// This test ensures that Readable stream will continue to call _read
61cb0ef41Sopenharmony_ci// for streams with highWaterMark === 0 once the stream returns data
71cb0ef41Sopenharmony_ci// by calling push() asynchronously.
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_ciconst { Readable } = require('stream');
101cb0ef41Sopenharmony_ci
111cb0ef41Sopenharmony_cilet count = 5;
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_ciconst r = new Readable({
141cb0ef41Sopenharmony_ci  // Called 6 times: First 5 return data, last one signals end of stream.
151cb0ef41Sopenharmony_ci  read: common.mustCall(() => {
161cb0ef41Sopenharmony_ci    process.nextTick(common.mustCall(() => {
171cb0ef41Sopenharmony_ci      if (count--)
181cb0ef41Sopenharmony_ci        r.push('a');
191cb0ef41Sopenharmony_ci      else
201cb0ef41Sopenharmony_ci        r.push(null);
211cb0ef41Sopenharmony_ci    }));
221cb0ef41Sopenharmony_ci  }, 6),
231cb0ef41Sopenharmony_ci  highWaterMark: 0,
241cb0ef41Sopenharmony_ci});
251cb0ef41Sopenharmony_ci
261cb0ef41Sopenharmony_cir.on('end', common.mustCall());
271cb0ef41Sopenharmony_cir.on('data', common.mustCall(5));
28

Indexes created Thu Nov 07 10:32:03 CST 2024