當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。