Created
September 23, 2010 04:07
-
-
Save kriskowal/593076 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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