Skip to content

Iteration consuming the heap is maybe too surprising #660

@jedwards1211

Description

@jedwards1211

It's good the changelog documents this behavior, but I had mistakenly assumed iterating Symbol.iterator would just read out the raw backing array in unsorted order.

My assumption had a significant consequence, I had a debug route for fetching the internal state of some algorithms out of my server, and I was including [...this.heap] in the response, and after awhile I realized that requesting this internal state was accidentally emptying the queues.

Making this library have an interface familiar to users of libraries in other languages is only convenient up to the point that it goes against the conventions JS users are used to. And I think iteration not consuming underlying data is one of those conventions in JS. I'm aware of async iteration that consumes underlying data (e.g. async iterating a ReadableStream) but not sync iteration. I don't think the Python heapq behavior should win over conventions.

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions