Allow multiple readers to iterate over a stream at the same time
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- JavaScript
- Star
- 122k
- Fork
- 37.3k
- Merge trung bình
- 4 ngày 2 giờ
- Pull request đã merge (30 ngày)
- 283
Mô tả
What is the problem this feature will solve?
When multiple callers use Readable[Symbol.asyncIterator], each caller receives a partial result.
import {Readable} from 'node:stream'
const stream = Readable.from(['a', 'b', 'c'])
const iterate = async (readerName) => {
for await (const chunk of stream) {
console.log(readerName, chunk)
}
}
await Promise.all([
iterate('one'),
iterate('two'),
])
one a
two b
one c
Some callers might expect that result. But others might expect the following result instead.
one a
two a
one b
two b
one c
two c
What is the feature you are proposing to solve the problem?
Adding an option to readable.iterator() to use readable.on('data') instead of readable.read(). This would enable the above behavior.
What alternatives have you considered?
Implementing this user-land.
See an example of it at https://github.com/sindresorhus/get-stream/pull/121
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu trong lib/internal/streams/readable.js tại Readable[Symbol.asyncIterator] và kiểm tra cách readable.iterator() hiện tiêu thụ stream. So sánh hành vi data-event được đề xuất với ví dụ lặp đồng thời được cung cấp; hoàn tất nghĩa là một tùy chọn được định nghĩa và nhiều reader nhận được từng chunk như được tài liệu hóa.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- javascript, node.js
- Lĩnh vực
- api, backend
- Loại issue
- Tính năng
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 35/100