Browse Source

Add options to process.watchFile()

v0.7.4-release
Ryan Dahl 15 years ago
parent
commit
6de2173d7c
  1. 7
      doc/api.txt
  2. 19
      src/node.js
  3. 7
      src/node_stat.cc

7
doc/api.txt

@ -124,9 +124,14 @@ Send a signal to a process. +pid+ is the process id and +signal+ is the
signal to send; for example, "SIGINT" or "SIGUSR1". See kill(2) for more
information.
+process.watchFile(filename, listener)+::
+process.watchFile(filename, [options,] listener)+::
Watch for changes on +filename+. The callback +listener+ will be called each
time the file changes.
+
The second argument is optional. The +options+ if provided should be an
object containing two members a boolean, +persistent+, and +interval+, a
polling value in milliseconds. The default is +{persistent: true, interval:
0}+.
+process.unwatchFile(filename)+::
Stop watching for changes on +filename+.

19
src/node.js

@ -336,14 +336,29 @@ process.addListener("newListener", function (event) {
var statWatchers = {};
process.watchFile = function (filename, listener) {
process.watchFile = function (filename) {
var stat;
var options;
var listener;
if ("object" == typeof arguments[1]) {
options = arguments[1];
listener = arguments[2];
} else {
options = {};
listener = arguments[1];
}
if (options.persistent === undefined) options.persistent = true;
if (options.interval === undefined) options.persistent = 0;
if (filename in statWatchers) {
stat = statWatchers[filename];
} else {
statWatchers[filename] = new process.Stat();
stat = statWatchers[filename];
stat.start(filename, true);
stat.start(filename, options.persistent, options.interval);
}
stat.addListener("change", listener);
return stat;

7
src/node_stat.cc

@ -57,7 +57,12 @@ Handle<Value> Stat::Start(const Arguments& args) {
assert(handler->path_ == NULL);
handler->path_ = strdup(*path);
ev_stat_set(&handler->watcher_, handler->path_, 0.);
ev_tstamp interval = 0.;
if (args[2]->IsInt32()) {
interval = NODE_V8_UNIXTIME(args[2]);
}
ev_stat_set(&handler->watcher_, handler->path_, interval);
ev_stat_start(EV_DEFAULT_UC_ &handler->watcher_);
handler->persistent_ = args[1]->IsTrue();

Loading…
Cancel
Save