本文整理匯總了TypeScript中streamline-runtime._.funnel方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript _.funnel方法的具體用法?TypeScript _.funnel怎麽用?TypeScript _.funnel使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類streamline-runtime._
的用法示例。
在下文中一共展示了_.funnel方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: parallel
/// * `group = reader.parallel(count, consumer)`
/// Parallelizes by distributing the values to a set of `count` identical consumers.
/// `count` is the number of consumers that will be created.
/// `consumer` is a function with the following signature: `reader = consumer(source)`
/// Returns a `StreamGroup` on which other operations can be chained.
/// Note: transformed entries may be delivered out of order.
parallel(options: ParallelOptions | number, consumer: (source: any) => Reader<T>) {
var opts: ParallelOptions;
if (typeof options === "number") opts = {
count: options,
};
else opts = options;
const parent = this;
const streams: Reader<T>[] = [];
const funnel = _.funnel(1);
var inside = 0;
var stopArg: any;
for (var i = 0; i < opts.count; i++) {
((i: number) => { // i for debugging
streams.push(consumer(new Reader(function read(_) {
if (stopArg) {
if (stopArg === true) return undefined;
else throw stopArg;
}
return funnel(_, (_) => {
if (inside++ !== 0) throw new Error("funnel error: " + inside);
var val = parent.read(_);
inside--;
return val;
});
}, function stop(_, arg) {
if (stopArg) return;
stopArg = arg;
parent.stop(_, arg);
}, parent)));
})(i);
}
const group = new StreamGroup(streams);
return opts.shuffle ? group.dequeue() : group.rr();
}