I have never used RSVP, I am more familiar with [Q][1]Q, but I believe following should do what you need:
var evaluate = function (xmlDoc) {
TokenData = xmlDoc.evaluate(
'/root/theToken',
xmlDoc.documentElement,
null,
XPathResult.FIRST_ORDERED_NODE_TYPE,
null).singleNodeValue.textContent;
return TokenData;
}
RSVP.resolve(TokenData || LoadURIPromise(TokenURL).then(evaluate))
.then(function (token) {
//Use Token here
console.info(token);
});
Here is working [jsFiddle][2]jsFiddle
BTW, do you really need TokenData
to be global?
[1]: https://github.com/kriskowal/q
[2]: http://jsfiddle.net/tomalec/EsRkp/2/