Allow multiple readers to iterate over a stream at the same time
Nessuno ha ancora preso questa issue.
- Lingua principale
- JavaScript
- Stelle
- 122k
- Fork
- 37.3k
- Merge medio
- 4g 2h
- PR unite (30g)
- 283
Descrizione
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
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia in lib/internal/streams/readable.js, in Readable[Symbol.asyncIterator], e verifica come readable.iterator() consuma attualmente lo stream. Confronta il comportamento proposto di data-event con l’esempio fornito di iterazione concorrente; completato significa che è definita un’opzione e che più lettori ricevono ogni chunk come documentato.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- javascript, node.js
- Ambito
- api, backend
- Tipo di issue
- Funzionalità
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100