本文整理汇总了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]);
}
});
}
示例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);
//.........这里部分代码省略.........