0

RemoveListener?

crabicode 8 jaar geleden in iRidium Script bijgewerkt 8 jaar geleden 7

Hi,


Can anyone help me find a solution to this scenario:


var object = {};
IR.AddListener(EVENT_RECEIVE_TEXT, 0, function(data) {
// this is called only once
}, object);

object is now referenced within the event loop and can't be garbage collected.

Assuming multiple cases like that, what is the best approach to deal with it?

I guess there must be a way to unbind the handler aka RemoveListener...


Any ideas?


Regards

Sorry not sure what you mean. What do you want to do?

Considereing async nature of js event-driven env.

The major issue that I am concerned with is that I have two http devices I want to sync their responses and wait for each of them to resolve.

I want to keep track of requests' responses

IR.AddListener(EVENT_RECIEVE_TEXT, device, function(text) { 
    // response for request 1
});
// request 1 -> success
device.send(['request']);
// request 2 -> fail
device.send(['fail']);

For example, I do constantly send many http requests and therefore would like to track them down to know which of them has failed or succeeded.


How can I track responses for a single SEND call so I am able to know exactly that a response corresponds to some request?


Something similar to cbReceiveText http://dev.iridiummobile.net/Drivers_API#.SendEx in iR3 but for iR2

+1

You would monitor the feedback in EVENT_RECEIVE_TEXT as you identified, and it depends on the format of your responses as to how you would break it up and examine whether it was successful or not


You may want to not send the next request until the response is received, or build this in as a debug option :)


Have a look at the weather javascript module for an example using JSON

+1

Re

"Considereing async nature of js event-driven env.The major issue that I am concerned with is that I have two http devices I want to sync their responses and wait for each of them to resolve"

So you might have something like:


- 2 x global variable outside both drivers with possible values 0 - sending, 1 - positive response, 2 - negative response

- 2 x EVENT_RECEIVE_TEXT, setting the global variable to 1 or 2

- send command to set global variable to 0

- have an IR.SetInterval started on send and checking regularly to see if value of each of the variable have changed.

- You might also set a time out that says after eg 20 or so seconds of sending it is a negative response.


I am not a JavaScript expert so there may be a better way to do this :)

Appreciate your follow ups! Will think over to find out :)