Callback ids cycle from 0 to 1000
This commit is contained in:
parent
51abcc6953
commit
1f455c813a
1 changed files with 22 additions and 4 deletions
|
@ -196,17 +196,35 @@ weechat.factory('connection', ['$q', '$rootScope', '$log', '$store', 'handlers',
|
||||||
var callbacks = {}
|
var callbacks = {}
|
||||||
var currentCallBackId = 0;
|
var currentCallBackId = 0;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Returns the current callback id
|
||||||
|
*/
|
||||||
|
var getCurrentCallBackId = function() {
|
||||||
|
|
||||||
|
currentCallBackId += 1;
|
||||||
|
|
||||||
|
if (currentCallBackId > 1000) {
|
||||||
|
currentCallBackId = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return currentCallBackId;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Create a callback, adds it to the callback list
|
* Create a callback, adds it to the callback list
|
||||||
* and return it.
|
* and return it.
|
||||||
*/
|
*/
|
||||||
var createCallback = function() {
|
var createCallback = function() {
|
||||||
var defer = $q.defer();
|
var defer = $q.defer();
|
||||||
callbacks[++currentCallBackId] = {
|
var cbId = getCurrentCallBackId();
|
||||||
|
|
||||||
|
callbacks[cbId] = {
|
||||||
time: new Date,
|
time: new Date,
|
||||||
cb: defer
|
cb: defer,
|
||||||
}
|
}
|
||||||
callBackIdString = "(" + currentCallBackId + ")";
|
|
||||||
|
defer.id = cbId
|
||||||
|
|
||||||
return defer;
|
return defer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -232,7 +250,7 @@ weechat.factory('connection', ['$q', '$rootScope', '$log', '$store', 'handlers',
|
||||||
var send = function(message) {
|
var send = function(message) {
|
||||||
message.replace(/[\r\n]+$/g, "").split("\n");
|
message.replace(/[\r\n]+$/g, "").split("\n");
|
||||||
var cb = createCallback(message);
|
var cb = createCallback(message);
|
||||||
websocket.send(callBackIdString + " " + message);
|
websocket.send("(" + cb.id + ") " + message);
|
||||||
return cb.promise;
|
return cb.promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue