fs: make fs.watchFile() interval default to 5007

This commit is contained in:
Ben Noordhuis 2012-06-21 15:03:21 +02:00
parent f0ce98441f
commit ef1ffcb717
3 changed files with 14 additions and 34 deletions

View File

@ -912,14 +912,20 @@ function inStatWatchers(filename) {
fs.watchFile = function(filename) {
var stat;
var options;
var listener;
var options = {
// Poll interval in milliseconds. 5007 is what libev used to use. It's
// a little on the slow side but let's stick with it for now to keep
// behavioral changes to a minimum.
interval: 5007,
persistent: true,
};
if ('object' == typeof arguments[1]) {
options = arguments[1];
options = util._extend(options, arguments[1]);
listener = arguments[2];
} else {
options = {};
listener = arguments[1];
}
@ -927,9 +933,6 @@ fs.watchFile = function(filename) {
throw new Error('watchFile requires a listener function');
}
if (options.persistent === undefined) options.persistent = true;
if (options.interval === undefined) options.interval = 0;
if (inStatWatchers(filename)) {
stat = statWatchers[filename];
} else {

View File

@ -25,11 +25,6 @@
#include <string.h>
#include <stdlib.h>
// Poll interval in milliseconds. 5007 is what libev used to use. It's a little
// on the slow side but let's stick with it for now, keep behavioral changes to
// a minimum.
#define DEFAULT_POLL_INTERVAL 5007
namespace node {
using namespace v8;
@ -76,10 +71,7 @@ void StatWatcher::Callback(uv_fs_poll_t* handle,
Handle<Value> StatWatcher::New(const Arguments& args) {
if (!args.IsConstructCall()) {
return FromConstructorTemplate(constructor_template, args);
}
assert(args.IsConstructCall());
HandleScope scope;
StatWatcher* s = new StatWatcher();
s->Wrap(args.Holder());
@ -88,28 +80,16 @@ Handle<Value> StatWatcher::New(const Arguments& args) {
Handle<Value> StatWatcher::Start(const Arguments& args) {
assert(args.Length() == 3);
HandleScope scope;
if (args.Length() < 1 || !args[0]->IsString()) {
return ThrowException(Exception::TypeError(String::New("Bad arguments")));
}
StatWatcher* wrap = ObjectWrap::Unwrap<StatWatcher>(args.Holder());
String::Utf8Value path(args[0]);
const bool persistent = args[1]->BooleanValue();
const uint32_t interval = args[2]->Uint32Value();
uint32_t interval = DEFAULT_POLL_INTERVAL;
if (args[2]->IsUint32()) {
interval = args[2]->Uint32Value();
}
if (!persistent) uv_unref(reinterpret_cast<uv_handle_t*>(&wrap->watcher_));
uv_fs_poll_start(&wrap->watcher_, Callback, *path, interval);
wrap->persistent_ = args[1]->IsTrue();
if (!wrap->persistent_) {
uv_unref(reinterpret_cast<uv_handle_t*>(&wrap->watcher_));
}
wrap->Ref();
return Undefined();

View File

@ -35,7 +35,6 @@ class StatWatcher : ObjectWrap {
static v8::Persistent<v8::FunctionTemplate> constructor_template;
StatWatcher() : ObjectWrap() {
persistent_ = false;
uv_fs_poll_init(uv_default_loop(), &watcher_);
}
@ -52,11 +51,9 @@ class StatWatcher : ObjectWrap {
int status,
const uv_statbuf_t* prev,
const uv_statbuf_t* curr);
void Stop();
uv_fs_poll_t watcher_;
bool persistent_;
};
} // namespace node