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


TypeScript IMessagePassingProtocol.onMessage方法代码示例

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


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

示例1: constructor

	constructor(protocol: IMessagePassingProtocol, onMessage: (msg: string) => void) {
		this._protocol = protocol;
		this._sendAccumulatedBound = this._sendAccumulated.bind(this);

		this._messagesToSend = [];

		this._protocol.onMessage(data => {
			for (let i = 0, len = data.length; i < len; i++) {
				onMessage(data[i]);
			}
		});
	}
开发者ID:SeanKilleen,项目名称:vscode,代码行数:12,代码来源:rpcProtocol.ts

示例2: createProxyProtocol

export function createProxyProtocol(protocol: IMessagePassingProtocol): IRemoteCom {
	let rpc = createRPC(sendDelayed);
	let bigHandler: IManyHandler = null;
	let invokedHandlers: { [req: string]: winjs.TPromise<any>; } = Object.create(null);
	let messagesToSend: string[] = [];

	let messagesToReceive: string[] = [];
	let receiveOneMessage = () => {
		let rawmsg = messagesToReceive.shift();

		if (messagesToReceive.length > 0) {
			process.nextTick(receiveOneMessage);
		}

		let msg = marshalling.parse(rawmsg);

		if (msg.seq) {
			if (!pendingRPCReplies.hasOwnProperty(msg.seq)) {
				console.warn('Got reply to unknown seq');
				return;
			}
			let reply = pendingRPCReplies[msg.seq];
			delete pendingRPCReplies[msg.seq];

			if (msg.err) {
				let err = msg.err;
				if (msg.err.$isError) {
					err = new Error();
					err.name = msg.err.name;
					err.message = msg.err.message;
					err.stack = msg.err.stack;
				}
				reply.resolveErr(err);
				return;
			}

			reply.resolveOk(msg.res);
			return;
		}

		if (msg.cancel) {
			if (invokedHandlers[msg.cancel]) {
				invokedHandlers[msg.cancel].cancel();
			}
			return;
		}

		if (msg.err) {
			console.error(msg.err);
			return;
		}

		let rpcId = msg.rpcId;

		if (!bigHandler) {
			throw new Error('got message before big handler attached!');
		}

		let req = msg.req;

		invokedHandlers[req] = invokeHandler(rpcId, msg.method, msg.args);

		invokedHandlers[req].then((r) => {
			delete invokedHandlers[req];
			sendDelayed(MessageFactory.replyOK(req, r));
		}, (err) => {
			delete invokedHandlers[req];
			sendDelayed(MessageFactory.replyErr(req, err));
		});
	};

	protocol.onMessage(data => {
		// console.log('RECEIVED ' + rawmsg.length + ' MESSAGES.');
		if (messagesToReceive.length === 0) {
			process.nextTick(receiveOneMessage);
		}

		messagesToReceive = messagesToReceive.concat(data);
	});

	let r: IRemoteCom = {
		callOnRemote: rpc,
		setManyHandler: (_bigHandler: IManyHandler): void => {
			bigHandler = _bigHandler;
		}
	};

	function sendAccumulated(): void {
		let tmp = messagesToSend;
		messagesToSend = [];

		// console.log('SENDING ' + tmp.length + ' MESSAGES.');
		protocol.send(tmp);
	}

	function sendDelayed(value: string): void {
		if (messagesToSend.length === 0) {
			process.nextTick(sendAccumulated);
		}
		messagesToSend.push(value);
//.........这里部分代码省略.........
开发者ID:Chan-PH,项目名称:vscode,代码行数:101,代码来源:ipcRemoteCom.ts


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