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


TypeScript _.run方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: end

		const more = () => {
			if (pending) return;
			var sync = true;
			pending = true;
			_.run(_ => this.read(_), (err, result) => {
				pending = false;
				if (err) return stream.emit('error', err);
				if (result === undefined) {
					if (sync) nextTick(end);
					else end();
					return;
				}
				if (stream.push(result)) {
					if (sync) nextTick(more);
					else more();
				}
			});
			sync = false;
		}
开发者ID:Sage,项目名称:ez-streams,代码行数:19,代码来源:reader.ts

示例6:

			const next = () => {
				if (alive === 0) return;
				_.run(_ => stream.read(_), (e, v) => {
					if (!e && v === undefined) alive--;
					if (e || v !== undefined || alive === 0) {
						if (resume) {
							var cb = resume;
							resume = undefined;
							cb(e, v);
							next();
						} else {
							results.push({
								i: i,
								e: e,
								v: v,
								next: next,
							});
						}
					}
				});
			};
开发者ID:Sage,项目名称:ez-streams,代码行数:21,代码来源:reader.ts

示例7: if

		const fill = () => {
			if (pending) return;
			pending = true;
			_.run(_ => parent.read(_), (e, v) => {
				pending = false;
				if (e) err = err || e;
				else buffered.push(v);

				if (resume) {
					var cb = resume;
					resume = undefined;
					if (buffered.length > 0) {
						v = buffered.shift();
						fill();
						cb(null, v);
					} else {
						cb(err)
					}
				} else if (buffered.length < max) {
					if (!err && v !== undefined) fill();
				}
			});
		}
开发者ID:Sage,项目名称:ez-streams,代码行数:23,代码来源:reader.ts

示例8: connectionListener

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

示例9: du

 *
 * Demonstrates how standard asynchronous node.js functions
 * like fs.stat, fs.readdir, fs.readFile can be called from 'streamlined'
 * Javascript code.
 */
import { _ } from 'streamline-runtime';
import * as fs from 'fs';

function du(_: _, path: string) {
  var total = 0;
  var stat = fs.stat(path, _);
  if (stat.isFile()) {
    total += fs.readFile(path, _).length;
  } else if (stat.isDirectory()) {
    var files = fs.readdir(path, _);
    for (var i = 0; i < files.length; i++) {
      total += du(_, path + "/" + files[i]);
    }
    console.log(path + ": " + total);
  } else {
    console.log(path + ": odd file");
  }
  return total;
}

var p = process.argv.length > 2 ? process.argv[2] : ".";
var t0 = Date.now();
_.run(_ => du(_, p), err => {
    if (err) throw err;
    console.log("completed in " + (Date.now() - t0) + " ms");
});
开发者ID:Sage,项目名称:streamlinejs,代码行数:31,代码来源:diskUsage.ts

示例10: end

	/// 
	/// * `writer = writer.end()`  
	///   ends the writer - compatiblity call (errors won't be thrown to caller)
	end() {
		if (arguments.length > 0) throw new Error("invalid end call: " + arguments.length + " arg(s)");
		_.run(_ => this.write(_, undefined));
		return this;
	};
开发者ID:Sage,项目名称:ez-streams,代码行数:8,代码来源:writer.ts


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