Commit 8c70d38b by Thimo Kraemer

Prevent simultaneous requests for each server action

parent 25405a73
/*
* KSS-RPC v0.19-beta
* KSS-RPC v0.20-beta
*
* Copyright (c) 2017, joonis new media
* Author: Thimo Kraemer <thimo.kraemer@joonis.de>
......@@ -61,7 +61,7 @@
******************************************************************************************/
var kss = {
version: '0.19-beta',
version: '0.20-beta',
_initialized: false,
_ruleSheets: {},
_eventBinders: {},
......@@ -672,10 +672,11 @@ kss._EventHandler = function(node, eventname, rule, initial) {
this.eventname = eventname;
this.event = {};
this.rule = rule;
this._queuedActions = {};
// Get kss- properties
this.kssProps = this.propertyGetter({
selector: '@samenode',
precondition: true,
precondition: true
}, rule.props);
// Get evt- properties
this.evtProps = this.propertyGetter({
......@@ -835,10 +836,14 @@ kss._EventHandler.prototype = {
},
_execServerAction: function(name, params, timeout) {
// Prevent server actions for mouse moves
if (['mousemove','drag','dragover'].indexOf(this.eventname) > -1) {
// Action queue
if (name in this._queuedActions) {
this.debug('Queued server action "'
+ name + '" and dropped previous');
this._queuedActions[name] = [params, timeout];
return;
}
this._queuedActions[name] = null;
var config = Object.create(this.rule.config);
if (timeout) {
config.timeout = timeout;
......@@ -849,10 +854,22 @@ kss._EventHandler.prototype = {
params = [params];
}
this._callBinders('onstart', action);
var self = this;
function completed(error) {
if (error)
self.error(error);
self._callBinders('oncomplete', action, error);
var args = self._queuedActions[name];
delete self._queuedActions[name];
if (args) {
self._execServerAction(name, args[0], args[1]);
}
}
try {
var msg = this.time('Execute server action "' + name + '"');
var rpc = new kss.RPC(config.endpoint, config);
var self = this;
rpc.invoke(name, params,
function(result) {
var error;
......@@ -873,20 +890,15 @@ kss._EventHandler.prototype = {
});
}
catch (err) {
self.error(err);
error = err;
}
self._callBinders('oncomplete', action, error);
completed(error);
},
function(err) {
self.error(err);
self._callBinders('oncomplete', action, err);
}
completed
);
}
catch (err) {
this.error(err);
this._callBinders('oncomplete', action, err);
completed(err);
}
},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment