You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cordova.apache.org by "Peter (JIRA)" <ji...@apache.org> on 2013/06/18 08:29:19 UTC
[jira] [Created] (CB-3901) Backlog of Acceleration messages are
received after plugin/sensor is stopped
Peter created CB-3901:
-------------------------
Summary: Backlog of Acceleration messages are received after plugin/sensor is stopped
Key: CB-3901
URL: https://issues.apache.org/jira/browse/CB-3901
Project: Apache Cordova
Issue Type: Improvement
Components: Android, CordovaJS
Affects Versions: 2.7.0
Reporter: Peter
Assignee: Joe Bowser
Priority: Minor
There is a kind of race condition between the Accelerometer events being generated and the processing of the Cordova bridge messages.
For example:
In the plugin:
* Accelerometer events are generated at a rapid rate.
* The event always results in data transfer across the bridge. e.g. onSensorChanged calls this.win() calls sendPluginResult…
* So very quickly lots of PluginResult messages will be queued, requiring processing
Meanwhile in the JavaScript:
* callbackFromNative handles the incoming messages and if there are any listeners then it deals with the acceleration event.
* When it determines there are no user listeners left then a sensor “stop” will be issued
But even after the “stop” is executed, there is still a potentially large backlog of queued acceleration messages still remaining to be processed.
Since there are no user listeners left the user does not get to see them – they so just end up going nowhere.
I don’t know whether there is anything possible that can be done about this (it seems to be just the way it is designed) but perhaps there should be some comment in the code for the accelerometer callbacks to describe how they may be called even though all user listeners have been removed. And maybe the success function can be modified to not bother constructing the Acceleration instance unless it will be used. Something like this?
BEFORE:
{code}
function(a) {
var tempListeners = listeners.slice(0);
accel = new Acceleration(a.x, a.y, a.z, a.timestamp);
for (var i = 0, l = tempListeners.length; i < l; i++) {
tempListeners[i].win(accel);
}
}
{code}
AFTER:
{code}
function(a) {
// NB: It is possible for this callback to be executed even after the accelerometer
// sensor is “stopped” due to a backlog of unprocessed acceleration messages.
var tempListeners = listeners.slice(0);
var nListeners = tempListeners.length;
if (nListeners > 0) {
accel = new Acceleration(a.x, a.y, a.z, a.timestamp);
for (var i = 0, l = nListeners; i < l; i++) {
tempListeners[i].win(accel);
}
}
}
{code}
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira