blob: 1d5a55990f41aab690a837e13d52027920406c7b [file] [log] [blame]
// Copyright 2015 The Vanadium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
/**
* @fileoverview Channel RPCs where all messages are enqueued until a ready
* signal is received and then all RPC messages are sent.
*/
module.exports = QueuedRpcChannelWrapper;
function QueuedRpcChannelWrapper(rpcChannel) {
this._rpcChannel = rpcChannel;
this._ready = false;
this._queuedRpcs = [];
}
QueuedRpcChannelWrapper.prototype.registerRpcHandler = function(type, func) {
this._rpcChannel.registerRpcHandler(type, func);
};
QueuedRpcChannelWrapper.prototype.performRpc = function(type, val, callback) {
if (!this._ready) {
this._queuedRpcs.push({
type: type,
val: val,
callback: callback
});
return;
}
this._rpcChannel.performRpc(type, val, callback);
};
QueuedRpcChannelWrapper.prototype.ready = function() {
this._ready = true;
var rpcChannel = this._rpcChannel;
this._queuedRpcs.forEach(function(rpc) {
rpcChannel.performRpc(rpc.type, rpc.val, rpc.callback);
});
};