fs: make fs.watchFile() interval default to 5007
This commit is contained in:
parent
f0ce98441f
commit
ef1ffcb717
15
lib/fs.js
15
lib/fs.js
@ -912,14 +912,20 @@ function inStatWatchers(filename) {
|
|||||||
|
|
||||||
fs.watchFile = function(filename) {
|
fs.watchFile = function(filename) {
|
||||||
var stat;
|
var stat;
|
||||||
var options;
|
|
||||||
var listener;
|
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]) {
|
if ('object' == typeof arguments[1]) {
|
||||||
options = arguments[1];
|
options = util._extend(options, arguments[1]);
|
||||||
listener = arguments[2];
|
listener = arguments[2];
|
||||||
} else {
|
} else {
|
||||||
options = {};
|
|
||||||
listener = arguments[1];
|
listener = arguments[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -927,9 +933,6 @@ fs.watchFile = function(filename) {
|
|||||||
throw new Error('watchFile requires a listener function');
|
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)) {
|
if (inStatWatchers(filename)) {
|
||||||
stat = statWatchers[filename];
|
stat = statWatchers[filename];
|
||||||
} else {
|
} else {
|
||||||
|
@ -25,11 +25,6 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.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 {
|
namespace node {
|
||||||
|
|
||||||
using namespace v8;
|
using namespace v8;
|
||||||
@ -76,10 +71,7 @@ void StatWatcher::Callback(uv_fs_poll_t* handle,
|
|||||||
|
|
||||||
|
|
||||||
Handle<Value> StatWatcher::New(const Arguments& args) {
|
Handle<Value> StatWatcher::New(const Arguments& args) {
|
||||||
if (!args.IsConstructCall()) {
|
assert(args.IsConstructCall());
|
||||||
return FromConstructorTemplate(constructor_template, args);
|
|
||||||
}
|
|
||||||
|
|
||||||
HandleScope scope;
|
HandleScope scope;
|
||||||
StatWatcher* s = new StatWatcher();
|
StatWatcher* s = new StatWatcher();
|
||||||
s->Wrap(args.Holder());
|
s->Wrap(args.Holder());
|
||||||
@ -88,28 +80,16 @@ Handle<Value> StatWatcher::New(const Arguments& args) {
|
|||||||
|
|
||||||
|
|
||||||
Handle<Value> StatWatcher::Start(const Arguments& args) {
|
Handle<Value> StatWatcher::Start(const Arguments& args) {
|
||||||
|
assert(args.Length() == 3);
|
||||||
HandleScope scope;
|
HandleScope scope;
|
||||||
|
|
||||||
if (args.Length() < 1 || !args[0]->IsString()) {
|
|
||||||
return ThrowException(Exception::TypeError(String::New("Bad arguments")));
|
|
||||||
}
|
|
||||||
|
|
||||||
StatWatcher* wrap = ObjectWrap::Unwrap<StatWatcher>(args.Holder());
|
StatWatcher* wrap = ObjectWrap::Unwrap<StatWatcher>(args.Holder());
|
||||||
String::Utf8Value path(args[0]);
|
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 (!persistent) uv_unref(reinterpret_cast<uv_handle_t*>(&wrap->watcher_));
|
||||||
if (args[2]->IsUint32()) {
|
|
||||||
interval = args[2]->Uint32Value();
|
|
||||||
}
|
|
||||||
|
|
||||||
uv_fs_poll_start(&wrap->watcher_, Callback, *path, interval);
|
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();
|
wrap->Ref();
|
||||||
|
|
||||||
return Undefined();
|
return Undefined();
|
||||||
|
@ -35,7 +35,6 @@ class StatWatcher : ObjectWrap {
|
|||||||
static v8::Persistent<v8::FunctionTemplate> constructor_template;
|
static v8::Persistent<v8::FunctionTemplate> constructor_template;
|
||||||
|
|
||||||
StatWatcher() : ObjectWrap() {
|
StatWatcher() : ObjectWrap() {
|
||||||
persistent_ = false;
|
|
||||||
uv_fs_poll_init(uv_default_loop(), &watcher_);
|
uv_fs_poll_init(uv_default_loop(), &watcher_);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,11 +51,9 @@ class StatWatcher : ObjectWrap {
|
|||||||
int status,
|
int status,
|
||||||
const uv_statbuf_t* prev,
|
const uv_statbuf_t* prev,
|
||||||
const uv_statbuf_t* curr);
|
const uv_statbuf_t* curr);
|
||||||
|
|
||||||
void Stop();
|
void Stop();
|
||||||
|
|
||||||
uv_fs_poll_t watcher_;
|
uv_fs_poll_t watcher_;
|
||||||
bool persistent_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace node
|
} // namespace node
|
||||||
|
Loading…
x
Reference in New Issue
Block a user