本文整理汇总了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();
}