提交 7e8384ba 编写于 作者: A Alex Dima

Execute just once after N changes

上级 c88064a3
......@@ -109,6 +109,7 @@ exports.watchTask = watchTask;
const REPO_SRC_FOLDER = path.join(__dirname, '../../src');
class MonacoGenerator {
constructor(isWatch) {
this._executeSoonTimer = null;
this._isWatch = isWatch;
this.stream = es.through();
this._inputFiles = monacodts.getIncludesInRecipe().map((moduleId) => {
......@@ -127,16 +128,14 @@ class MonacoGenerator {
const watcher = fs.watch(filePath);
watcher.addListener('change', () => {
this._inputFileChanged[filePath] = true;
// Avoid hitting empty files... :/
setTimeout(() => this.execute(), 10);
this._executeSoon();
});
this._watchers.push(watcher);
});
const recipeWatcher = fs.watch(monacodts.RECIPE_PATH);
recipeWatcher.addListener('change', () => {
this._recipeFileChanged = true;
// Avoid hitting empty files... :/
setTimeout(() => this.execute(), 10);
this._executeSoon();
});
this._watchers.push(recipeWatcher);
}
......@@ -146,6 +145,16 @@ class MonacoGenerator {
this._dtsFilesContents = {};
this._dtsFilesContents2 = {};
}
_executeSoon() {
if (this._executeSoonTimer !== null) {
// Already scheduled
return;
}
this._executeSoonTimer = setTimeout(() => {
this._executeSoonTimer = null;
this.execute();
}, 20);
}
dispose() {
this._watchers.forEach(watcher => watcher.close());
}
......
......@@ -166,8 +166,7 @@ class MonacoGenerator {
const watcher = fs.watch(filePath);
watcher.addListener('change', () => {
this._inputFileChanged[filePath] = true;
// Avoid hitting empty files... :/
setTimeout(() => this.execute(), 10);
this._executeSoon();
});
this._watchers.push(watcher);
});
......@@ -175,8 +174,7 @@ class MonacoGenerator {
const recipeWatcher = fs.watch(monacodts.RECIPE_PATH);
recipeWatcher.addListener('change', () => {
this._recipeFileChanged = true;
// Avoid hitting empty files... :/
setTimeout(() => this.execute(), 10);
this._executeSoon();
});
this._watchers.push(recipeWatcher);
}
......@@ -188,6 +186,18 @@ class MonacoGenerator {
this._dtsFilesContents2 = {};
}
private _executeSoonTimer: NodeJS.Timer | null = null;
private _executeSoon(): void {
if (this._executeSoonTimer !== null) {
// Already scheduled
return;
}
this._executeSoonTimer = setTimeout(() => {
this._executeSoonTimer = null;
this.execute();
}, 20);
}
public dispose(): void {
this._watchers.forEach(watcher => watcher.close());
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册