mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
Limiting watched file compilation to once every 25ms
This commit is contained in:
parent
9fde794858
commit
dfc602159e
2 changed files with 25 additions and 17 deletions
|
@ -188,20 +188,24 @@
|
|||
};
|
||||
|
||||
watch = function(source, base) {
|
||||
var callback, compile, prevStats, watchErr, watcher;
|
||||
var callback, compile, compileTimeout, prevStats, watchErr, watcher;
|
||||
prevStats = null;
|
||||
compileTimeout = null;
|
||||
compile = function() {
|
||||
return fs.stat(source, function(err, stats) {
|
||||
if (err) throw err;
|
||||
if (prevStats && (stats.size === prevStats.size && stats.mtime.getTime() === prevStats.mtime.getTime())) {
|
||||
return;
|
||||
}
|
||||
prevStats = stats;
|
||||
return fs.readFile(source, function(err, code) {
|
||||
clearTimeout(compileTimeout);
|
||||
return compileTimeout = setTimeout(function() {
|
||||
return fs.stat(source, function(err, stats) {
|
||||
if (err) throw err;
|
||||
return compileScript(source, code.toString(), base);
|
||||
if (prevStats && (stats.size === prevStats.size && stats.mtime.getTime() === prevStats.mtime.getTime())) {
|
||||
return;
|
||||
}
|
||||
prevStats = stats;
|
||||
return fs.readFile(source, function(err, code) {
|
||||
if (err) throw err;
|
||||
return compileScript(source, code.toString(), base);
|
||||
});
|
||||
});
|
||||
});
|
||||
}, 25);
|
||||
};
|
||||
watchErr = function(e) {
|
||||
if (e.code === 'ENOENT') {
|
||||
|
|
|
@ -168,16 +168,20 @@ loadRequires = ->
|
|||
watch = (source, base) ->
|
||||
|
||||
prevStats = null
|
||||
compileTimeout = null
|
||||
|
||||
compile = ->
|
||||
fs.stat source, (err, stats) ->
|
||||
throw err if err
|
||||
return if prevStats and (stats.size is prevStats.size and
|
||||
stats.mtime.getTime() is prevStats.mtime.getTime())
|
||||
prevStats = stats
|
||||
fs.readFile source, (err, code) ->
|
||||
clearTimeout compileTimeout
|
||||
compileTimeout = setTimeout ->
|
||||
fs.stat source, (err, stats) ->
|
||||
throw err if err
|
||||
compileScript(source, code.toString(), base)
|
||||
return if prevStats and (stats.size is prevStats.size and
|
||||
stats.mtime.getTime() is prevStats.mtime.getTime())
|
||||
prevStats = stats
|
||||
fs.readFile source, (err, code) ->
|
||||
throw err if err
|
||||
compileScript(source, code.toString(), base)
|
||||
, 25
|
||||
|
||||
watchErr = (e) ->
|
||||
if e.code is 'ENOENT'
|
||||
|
|
Loading…
Reference in a new issue