当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript _.funnel方法代码示例

本文整理汇总了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();
	}
开发者ID:Sage,项目名称:ez-streams,代码行数:41,代码来源:reader.ts


注:本文中的streamline-runtime._.funnel方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。