@@ -77,19 +77,15 @@ void StatWatcher::Initialize(Environment* env, Local<Object> target) {
77
77
78
78
StatWatcher::StatWatcher (Environment* env, Local<Object> wrap, bool use_bigint)
79
79
: AsyncWrap(env, wrap, AsyncWrap::PROVIDER_STATWATCHER),
80
- watcher_ (new uv_fs_poll_t ),
80
+ watcher_ (nullptr ),
81
81
use_bigint_(use_bigint) {
82
82
MakeWeak ();
83
- uv_fs_poll_init (env->event_loop (), watcher_);
84
- watcher_->data = static_cast <void *>(this );
85
83
}
86
84
87
85
88
86
StatWatcher::~StatWatcher () {
89
- if (IsActive ()) {
87
+ if (IsActive ())
90
88
Stop ();
91
- }
92
- env ()->CloseHandle (watcher_, [](uv_fs_poll_t * handle) { delete handle; });
93
89
}
94
90
95
91
@@ -123,7 +119,7 @@ void StatWatcher::New(const FunctionCallbackInfo<Value>& args) {
123
119
}
124
120
125
121
bool StatWatcher::IsActive () {
126
- return uv_is_active ( reinterpret_cast < uv_handle_t *>( watcher_)) != 0 ;
122
+ return watcher_ != nullptr ;
127
123
}
128
124
129
125
void StatWatcher::IsActive (const v8::FunctionCallbackInfo<v8::Value>& args) {
@@ -156,6 +152,9 @@ void StatWatcher::Start(const FunctionCallbackInfo<Value>& args) {
156
152
CHECK (args[2 ]->IsUint32 ());
157
153
const uint32_t interval = args[2 ].As <Uint32>()->Value ();
158
154
155
+ wrap->watcher_ = new uv_fs_poll_t ();
156
+ CHECK_EQ (0 , uv_fs_poll_init (wrap->env ()->event_loop (), wrap->watcher_ ));
157
+ wrap->watcher_ ->data = static_cast <void *>(wrap);
159
158
// Safe, uv_ref/uv_unref are idempotent.
160
159
if (persistent)
161
160
uv_ref (reinterpret_cast <uv_handle_t *>(wrap->watcher_ ));
@@ -187,7 +186,8 @@ void StatWatcher::Stop(const FunctionCallbackInfo<Value>& args) {
187
186
188
187
189
188
void StatWatcher::Stop () {
190
- uv_fs_poll_stop (watcher_);
189
+ env ()->CloseHandle (watcher_, [](uv_fs_poll_t * handle) { delete handle; });
190
+ watcher_ = nullptr ;
191
191
MakeWeak ();
192
192
}
193
193
0 commit comments