On Feb 8, 2006, at 6:41 PM, Matt Harrison wrote:

On 2/9/06, Bob Ippolito <[EMAIL PROTECTED]> wrote:

On Feb 8, 2006, at 5:01 PM, [EMAIL PROTECTED] wrote:

> Does anyone have an example of timing out an XMLHttpreques using
> Mochikit?
> I've got a server that just listens, but never responds and after like
> 5 seconds or so, I'd like my app to give up trying to get something
> back from it.

something like this should work:

var cancelWithTimeout = function (deferred, timeout) {
        var canceller = callLater(timeout, function () {
                // cancel the deferred after timeout seconds
                deferred.cancel();
        });
        return deferred.addCallback(function (res) {
                // if the deferred fires successfully, cancel the timeout
                canceller.cancel();
                return res;
        });
};


Used like this:

var d = cancelWithTimeout(10.0, loadJSONDoc(...));

Bob-

Thanks that worked (had to switch 10.0 to the 2nd parameter...).

Right -- that's what I get for writing code in Mail without testing it.

I've got another question for you regarding simplejson.  Have you (or anyone you know of) done serialization of python objects using JSON?

That's more or less what simplejson does by definition...  It won't serialize arbitrary objects out of the box, but it's easily subclassable in a way that would make it easy to do so (implementing a "default" method).

I'm thinking about how difficult it would be to do remote objects over http....

You mean like JSON-RPC?

-bob

Reply via email to