fs_event_wrap: update to new libuv api
authorTimothy J Fontaine <tjfontaine@gmail.com>
Tue, 29 Oct 2013 23:46:15 +0000 (16:46 -0700)
committerTimothy J Fontaine <tjfontaine@gmail.com>
Tue, 29 Oct 2013 23:46:15 +0000 (16:46 -0700)
src/fs_event_wrap.cc

index dad930a..4941ded 100644 (file)
@@ -108,17 +108,21 @@ void FSEventWrap::Start(const FunctionCallbackInfo<Value>& args) {
 
   String::Utf8Value path(args[0]);
 
-  int err = uv_fs_event_init(wrap->env()->event_loop(),
-                             &wrap->handle_,
-                             *path,
-                             OnEvent,
-                             0);
+  int err = uv_fs_event_init(wrap->env()->event_loop(), &wrap->handle_);
+
   if (err == 0) {
-    // Check for persistent argument
-    if (!args[1]->IsTrue()) {
-      uv_unref(reinterpret_cast<uv_handle_t*>(&wrap->handle_));
-    }
     wrap->initialized_ = true;
+
+    err = uv_fs_event_start(&wrap->handle_, OnEvent, *path, 0);
+
+    if (err == 0) {
+      // Check for persistent argument
+      if (!args[1]->IsTrue()) {
+        uv_unref(reinterpret_cast<uv_handle_t*>(&wrap->handle_));
+      }
+    } else {
+      FSEventWrap::Close(args);
+    }
   }
 
   args.GetReturnValue().Set(err);