Ensure addFilesPromise won't produce null pointers if the worker is terminated before it is finished.

This commit is contained in:
Erik Tierney committed 2013-05-24 14:36:53 -04:00
1 parent bdbef3de9a
commit 59783847a7
1 file changed
+11 -2
@@ -977,12 +977,21 @@ define(function (require, exports, module) {
* we know we will need to re-init it in any new project that is opened.
*/
function handleProjectClose() {
if (_ternWorker) {
function terminateWorker() {
_ternWorker.terminate();
_ternWorker = null;
ternPromise = null;
resolvedFiles = {};
}
if (_ternWorker) {
if (addFilesPromise) {
// If we're in the middle of added files, don't terminate
// until we're done or we might get NPEs
addFilesPromise.done(terminateWorker).fail(terminateWorker);
} else {
terminateWorker();
}
}
}
exports.getBuiltins = getBuiltins;