mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
Add options to process.watchFile()
This commit is contained in:
@@ -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
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;
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user