Skip to content

Instantly share code, notes, and snippets.

@kriskowal
Created September 23, 2010 04:07
Show Gist options
  • Save kriskowal/593076 to your computer and use it in GitHub Desktop.
Save kriskowal/593076 to your computer and use it in GitHub Desktop.
var Q = require("q");
exports.read = function (path, timeout) {
var response = Q.defer();
var request = new XMLHttpRequest(); // ActiveX blah blah
request.open("GET", path, true);
request.onreadystatechange = function () {
if (request.readyState === 4) {
if (request.status === 200) {
response.resolve(request.responseText);
} else {
response.reject("HTTP " + request.status + " for " + path);
}
}
};
timeout && setTimeout(response.reject, timeout);
request.send('');
return response.promise;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment