Page 1 of 1

Callbacks not removed from queue?

Posted: 18 Mar 2016, 18:53
by simpleSimon
I have written a server side extension and when I send an ExtensionRequest to it with javascript my callback is called once. But when I send to it a single time again, my callback is called twice. If I send to it again, my callback is called three times, and so on. Am I supposed to flush the response list some how? I have a little test form that has a button as follows:

<button type="button" onclick="listen('WK1234')">listen</button><br/><br/></body>

On the button click, a counter is initialized to count the callbacks. (code snippet follows). The results are:

click button the first time --> alert "responded (1): OK"
click button a second time --> alert "responded (1): OK" followed by alert "responded (2): OK"
click button again -> alert "responded (1): OK" followed by alert "responded (2): OK" followed by alert "responded (3): OK"

Code: Select all

function listen(uid)
{
   responseCounter = 0;
   sfs.addEventListener(SFS2X.SFSEvent.EXTENSION_RESPONSE, onListenResponse.bind(this), this);

   var params = {};
   params.uid = uid;

   sfs.send(new SFS2X.Requests.System.ExtensionRequest("listen", params));
}

function onListenResponse(evtParams)
{
   this.responseCounter++;
   alert("responded (" + this.responseCounter +") : " + evtParams.params.result);
}

Re: Callbacks not removed from queue?

Posted: 18 Mar 2016, 19:15
by simpleSimon
Never mind. I figured it out. Listeners are added as a list even when they are duplicate. I add a listener every time I click the listen button.

Re: Callbacks not removed from queue?

Posted: 19 Mar 2016, 14:23
by Lapo
Yes, that's correct :)