AsyncToken behaviour with Socket- Flex

188 Views Asked by At

I am using FlashSocket on my client side to make calls to socket.io on node.js server.

But i want specific values and function references to be available in the socket event listeners.

One approach that came to my mind was to pass the required values along with the request and make the server to send those parameters back along with the data. But that doesn't seem to help since I need the function handlers to be returned as well with the result.

The way i am doing it with http request is:

var token:AsyncToken = _service.send(item.params);
token.id = _tokenId;
token.params = item.params;
token.handler = item.resultHandler; // this would be called later in result or fault event handlers.

Is there a way to achieve this in flex sockets?

Thanks in advance.

1

There are 1 best solutions below

3
Petr Hrehorovsky On

You could use AsyncResponder class and anonymous functions.

var token:AsyncToken = _service.send(item.params);
token.addResponder(new AsyncResponder(
    function(event:Object, token:Object = null):void {
        // result handler, it has access to item.params, etc.
    },
    function(error:FaultEvent, token:Object = null):void {
        // fault handler, it has access to item.params, etc.
    }  
));