588
*/
589
export function listenStream<T>(stream: ReadableStreamEvents<T>, listener: IStreamListener<T>, token?: CancellationToken): void {
591
>
stream.on('error', error => {
592
if (!token?.isCancellationRequested) {
593
listener.onError(error);
594
}
596
>
597
>
stream.on('end', () => {
598
if (!token?.isCancellationRequested) {
599
listener.onEnd();
600
}
602
>
603
>
// Adding the `data` listener will turn the stream
604
>
// into flowing mode. As such it is important to
605
>
// add this listener last (DO NOT CHANGE!)
606
>
stream.on('data', data => {
607
if (!token?.isCancellationRequested) {
608
listener.onData(data);
609
}
611
>
}
612
613
/**