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


TypeScript streamline-runtime._类代码示例

本文整理汇总了TypeScript中streamline-runtime._的典型用法代码示例。如果您正苦于以下问题:TypeScript _类的具体用法?TypeScript _怎么用?TypeScript _使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了_类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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

示例2: connectionListener

		var emitter = net.createServer(serverOptions, (connection) => {
			_.withContext(() => {
				_.run(_ => connectionListener(new SocketStream(connection, streamOptions || {}), _), (err?: Error) => {
					if (err) throw err;
				});
			})();
		});
开发者ID:Sage,项目名称:ez-streams,代码行数:7,代码来源:node-wrappers.ts

示例3: listener

		return _.withContext(() => {
			return _.run(_ => listener(new HttpServerRequest(request, options), new HttpServerResponse(response, options), _), err => {
				// handlers do not read GET requests - so we remove the listeners, in case
				if (!/^(post|put)$/i.test(request.method || 'get')) request.removeAllListeners();
				if (err) throw err;
			});
		})();
开发者ID:Sage,项目名称:ez-streams,代码行数:7,代码来源:node-wrappers.ts

示例4: function

		anyStream._write = function (chunk: any, encoding?: string, done?: Function) {
			if (chunk && encoding && encoding !== 'buffer') chunk = chunk.toString(encoding);
			_.run(_ => self.write(_, chunk), err => {
				if (err) return stream.emit('error', err) as never;
				if (done) done();
			});
		}
开发者ID:Sage,项目名称:ez-streams,代码行数:7,代码来源:writer.ts

示例5: proxyConnect

	proxyConnect(_: _) {
		const options = this._options;
		if (options.isHttps) {
			// TODO: Don't authenticate with ntlm, nodejs raises "Parse error" in return of connect with 407 -> HPE_INVALID_CONSTANT
			return _.cast((callback: (err?: Error, resolved?: HttpClientRequest) => void) => {
				const proxyOpt = {
					host: options.proxy.host,
					port: options.proxy.port,
					method: 'CONNECT',
					path: options.host + ":" + options.port,
					headers: options.proxy.headers
				};
				var replied = false;
				// open proxy socket
				options.proxy.module.request(proxyOpt).on('connect', (res: never, socket: net.Socket, head: never) => {
					options.socket = socket;
					options.agent = false;
					//
					if (!replied) callback(undefined, new HttpClientRequest(options));
					replied = true;
				}).on('error', (err: Error) => {
					if (!replied) callback(err);
					replied = true;
				}).end();
				return this;
			})(_);
		} else {//
			if (options.proxyAuthenticate) {
				options.proxyAuthenticate(_, options);
			}
			return new HttpClientRequest(options);
		}
	}
开发者ID:Sage,项目名称:ez-streams,代码行数:33,代码来源:node-wrappers.ts

示例6: _drain

	_drain(_: _) {
		_.cast((callback: (err?: Error) => void) => {
			this._onDrain = (err) => {
				this._onDrain = nop;
				callback(err);
				callback = nop;
			};
		})(_);
	};
开发者ID:Sage,项目名称:ez-streams,代码行数:9,代码来源:node-wrappers.ts

示例7: end

	/// * `stream.end()`  
	///   signals the end of the send operation.  
	///   Returns `this` for chaining.
	end(data?: Data, enc?: string) {
		if (this.writer.ended) {
			if (data != null) throw new Error("invalid attempt to write after end");
			return this;
		}
		if (typeof data === "string") data = Buffer.from(data, enc || this._encoding || "utf8");
		else if (data === null) data = undefined;
		if (data !== undefined) {
			_.run(_ => this.writer.write(_, data), err => {
				if (err) throw err;
				this.end();
			});
		} else {
			_.run(_ => this.writer.write(_), err => {
				if (err) throw err;
			});
		}
		return this;
	}
开发者ID:Sage,项目名称:ez-streams,代码行数:22,代码来源:node-wrappers.ts

示例8: require

	/// * `reader = reader.transform(fn)`  
	///   Inserts an asynchronous transformation into chain.  
	///   This API is more powerful than `map` because the transformation function can combine results, split them, etc.  
	///   The transformation function `fn` is called as `fn(_, reader, writer)`
	///   where `reader` is the `stream` to which `transform` is applied,
	///   and writer is a writer which is piped into the next element of the chain.  
	///   Returns another reader on which other operations may be chained.
	transform<U>(fn: (_: _, reader: Reader<T>, writer: Writer<U>) => void, thisObj?: any): Reader<U> {
		thisObj = thisObj !== undefined ? thisObj : this;
		const parent = this;
		const uturn = require('./devices/uturn').create();
		_.run(_ => fn.call(thisObj, _, parent, uturn.writer), err => {
			// stop parent at end
			_.run(_ => parent.stop(_), e => {
				uturn.end(err || e);
			});
		});
		return uturn.reader;
	}
开发者ID:Sage,项目名称:ez-streams,代码行数:19,代码来源:reader.ts

示例9: return

	return (_: _, reader: Reader<Buffer>, writer: Writer<any>) => {
		const binReader = binary.reader(reader);
		const handshake = _.handshake();
		while (true) {
			var buf = binReader.readData(_, 2048);
			if (!buf || !buf.length) return;
			var str = buf.toString("binary");
			var i = str.indexOf(boundary);
			if (i < 0) throw new Error("boundary not found");
			var lines = str.substring(0, i).split(/\r?\n/);
			var headers = lines.slice(0, lines.length - 2).reduce((h: any, l: string) => {
				const kv = l.split(/\s*:\s*/);
				h[kv[0].toLowerCase()] = kv[1];
				return h;
			}, {});
			i = str.indexOf('\n', i);
			binReader.unread(buf.length - i - 1);

			var read = (_: _) => {
				const len = Math.max(boundary.length, 256);
				const buf = binReader.readData(_, 32 * len);
				if (!buf || !buf.length) {
					handshake.notify();
					return;
				}
				// would be nice if Buffer had an indexOf. Would avoid a conversion to string.
				// I could use node-buffertools but it introduces a dependency on a binary module.
				const s = buf.toString("binary");
				const i = s.indexOf(boundary);
				if (i === 0) {
					const j = s.indexOf('\n', boundary.length);
					if (j < 0) throw new Error("newline missing after boundary");
					binReader.unread(buf.length - j - 1);
					handshake.notify();
					return undefined;
				} else if (i > 0) {
					var j = s.lastIndexOf('\n', i);
					if (s[j - 1] === '\r') j--;
					binReader.unread(buf.length - i);
					return buf.slice(0, j);
				} else {
					binReader.unread(buf.length - 31 * len);
					return buf.slice(0, 31 * len);
				}
			};
			const partReader = generic.reader(read);
			partReader.headers = headers;
			writer.write(_, partReader);
			handshake.wait(_);
		}
	};
开发者ID:Sage,项目名称:ez-streams,代码行数:51,代码来源:multipart.ts

示例10:

		this.writer = generic.writer((_: _, data?: Data) => {
			if (this._error) throw new Error(this._error.message);
			// node streams don't differentiate between null and undefined. So end in both cases
			if (data != null) {
				// if data is empty do nothing but it's not to be interpreted as end
				if (!data.length) return this.writer;
				if (typeof data === "string") data = Buffer.from(data, this._encoding || "utf8");
				//
				if (!this._emitter.write(data)) this._drain(_);
			} else {
				_.cast(this._emitter.end).call(this._emitter, _);
			}
			return this.writer;
		});
开发者ID:Sage,项目名称:ez-streams,代码行数:14,代码来源:node-wrappers.ts


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