function setDeferredTimeout(deferred, delay) {
        var timer = setTimeout(function () {
            deferred.reject("timeout");
        }, delay);
        deferred.always(function () { clearTimeout(timer); });
    }
@private
Helper function to auto-reject a deferred after a given amount of time.
If the deferred is resolved/rejected manually, then the timeout is
automatically cleared.