當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript ipc.IMessagePassingProtocol類代碼示例

本文整理匯總了TypeScript中vs/base/parts/ipc/common/ipc.IMessagePassingProtocol的典型用法代碼示例。如果您正苦於以下問題:TypeScript IMessagePassingProtocol類的具體用法?TypeScript IMessagePassingProtocol怎麽用?TypeScript IMessagePassingProtocol使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了IMessagePassingProtocol類的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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

示例3: sendAccumulated

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

		// console.log('SENDING ' + tmp.length + ' MESSAGES.');
		protocol.send(tmp);
	}
開發者ID:Chan-PH,項目名稱:vscode,代碼行數:7,代碼來源:ipcRemoteCom.ts

示例4: _sendAccumulated

	private _sendAccumulated(): void {
		const tmp = this._messagesToSend;
		this._messagesToSend = [];
		this._protocol.send(tmp);
	}
開發者ID:SeanKilleen,項目名稱:vscode,代碼行數:5,代碼來源:rpcProtocol.ts


注:本文中的vs/base/parts/ipc/common/ipc.IMessagePassingProtocol類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。