Skip to content

Stream: Error trying to paginate data using Readable.take operator #44026

Open
@ErickWendel

Description

@ErickWendel

Version

18.4

Platform

Darwin

Subsystem

No response

What steps will reproduce the bug?

I was trying to paginate results from a Stream using the .take operator but it's throwing an AbortError

import {  Readable } from 'node:stream'
const data = Readable.from(['a', 'b', 'c', 'd'])
data.take(1).forEach(x => console.log(x));
data.take(2).forEach(x => console.log(x));
// AbortError: The operation was aborted

or

import {  Readable } from 'node:stream'
const data = Readable.from(['a', 'b', 'c'])
data.take(1).pipe(process.stdout)
data.take(2).pipe(process.stdout)
// AbortError: The operation was aborted

However, using the code below keeps the stream working and prints the array without one char

import {  Readable } from 'node:stream'
const data = Readable.from(['a', 'b', 'c', 'd'])
data.take(2).forEach(x => console.log(x, 'take 2'));
data.drop(1).take(1).forEach(x => console.log(x, 'drop 1 + take 1'));

/*
a take 2
d take 2
c drop 1 + take 1
*/

or

import {  Readable } from 'node:stream'
const data = Readable.from(['a', 'b', 'c'])
data.take(1).pipe(process.stdout)
data.drop(1).take(2).pipe(process.stdout)
//ac

How often does it reproduce? Is there a required condition?

No response

What is the expected behavior?

Consume chunks as specified

const data = Readable.from(['a', 'b', 'c'])
data.take(1).pipe(process.stdout)
data.take(2).pipe(process.stdout)
// abc

What do you see instead?

// AbortError: The operation was aborted

Additional information

@benjamingr

Metadata

Metadata

Assignees

No one assigned

    Labels

    streamIssues and PRs related to the stream subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions