readable.compose(stream[, options])
稳定性: 1 - 实验
stream<Stream> | <Iterable> | <AsyncIterable> | <Function>options<Object>signal<AbortSignal> 如果信号被中止,则允许销毁流。
- 返回: <Duplex> 由流
stream组成的流。
import { Readable } from 'node:stream';
async function* splitToWords(source) {
for await (const chunk of source) {
const words = String(chunk).split(' ');
for (const word of words) {
yield word;
}
}
}
const wordsStream = Readable.from(['this is', 'compose as operator']).compose(splitToWords);
const words = await wordsStream.toArray();
console.log(words); // 打印 ['this', 'is', 'compose', 'as', 'operator']有关详细信息,请参阅 stream.compose。
Stability: 1 - Experimental
stream<Stream> | <Iterable> | <AsyncIterable> | <Function>options<Object>signal<AbortSignal> allows destroying the stream if the signal is aborted.
- Returns: <Duplex> a stream composed with the stream
stream.
import { Readable } from 'node:stream';
async function* splitToWords(source) {
for await (const chunk of source) {
const words = String(chunk).split(' ');
for (const word of words) {
yield word;
}
}
}
const wordsStream = Readable.from(['this is', 'compose as operator']).compose(splitToWords);
const words = await wordsStream.toArray();
console.log(words); // prints ['this', 'is', 'compose', 'as', 'operator']See stream.compose for more information.