| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent b8bccc3 commit cf2475c
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -12,13 +12,14 @@ TimerWrap::TimerWrap(Environment* env, const TimerCb& fn) | |||
| 12 | 12 | timer_.data = this; | |
| 13 | 13 | } | |
| 14 | 14 | ||
| 15 | - void TimerWrap::Stop(bool close) { | ||
| 15 | + void TimerWrap::Stop() { | ||
| 16 | 16 | if (timer_.data == nullptr) return; | |
| 17 | 17 | uv_timer_stop(&timer_); | |
| 18 | - if (LIKELY(close)) { | ||
| 19 | - timer_.data = nullptr; | ||
| 20 | - env_->CloseHandle(reinterpret_cast<uv_handle_t*>(&timer_), TimerClosedCb); | ||
| 21 | - } | ||
| 18 | + } | ||
| 19 | + | ||
| 20 | + void TimerWrap::Close() { | ||
| 21 | + timer_.data = nullptr; | ||
| 22 | + env_->CloseHandle(reinterpret_cast<uv_handle_t*>(&timer_), TimerClosedCb); | ||
| 22 | 23 | } | |
| 23 | 24 | ||
| 24 | 25 | void TimerWrap::TimerClosedCb(uv_handle_t* handle) { | |
@@ -54,13 +55,14 @@ TimerWrapHandle::TimerWrapHandle( | |||
| 54 | 55 | env->AddCleanupHook(CleanupHook, this); | |
| 55 | 56 | } | |
| 56 | 57 | ||
| 57 | - void TimerWrapHandle::Stop(bool close) { | ||
| 58 | - if (UNLIKELY(!close)) | ||
| 59 | - return timer_->Stop(close); | ||
| 58 | + void TimerWrapHandle::Stop() { | ||
| 59 | + return timer_->Stop(); | ||
| 60 | + } | ||
| 60 | 61 | ||
| 62 | + void TimerWrapHandle::Close() { | ||
| 61 | 63 | if (timer_ != nullptr) { | |
| 62 | 64 | timer_->env()->RemoveCleanupHook(CleanupHook, this); | |
| 63 | - timer_->Stop(); | ||
| 65 | + timer_->Close(); | ||
| 64 | 66 | } | |
| 65 | 67 | timer_ = nullptr; | |
| 66 | 68 | } | |
@@ -80,13 +82,13 @@ void TimerWrapHandle::Update(uint64_t interval, uint64_t repeat) { | |||
| 80 | 82 | timer_->Update(interval, repeat); | |
| 81 | 83 | } | |
| 82 | 84 | ||
| 83 | - void TimerWrapHandle::CleanupHook(void* data) { | ||
| 84 | - static_cast<TimerWrapHandle*>(data)->Stop(); | ||
| 85 | - } | ||
| 86 | - | ||
| 87 | - void TimerWrapHandle::MemoryInfo(node::MemoryTracker* tracker) const { | ||
| 85 | + void TimerWrapHandle::MemoryInfo(MemoryTracker* tracker) const { | ||
| 88 | 86 | if (timer_ != nullptr) | |
| 89 | 87 | tracker->TrackField("timer", *timer_); | |
| 90 | 88 | } | |
| 91 | 89 | ||
| 90 | + void TimerWrapHandle::CleanupHook(void* data) { | ||
| 91 | + static_cast<TimerWrapHandle*>(data)->Close(); | ||
| 92 | + } | ||
| 93 | + | ||
| 92 | 94 | } // namespace node | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -21,14 +21,15 @@ class TimerWrap final : public MemoryRetainer { | |||
| 21 | 21 | ||
| 22 | 22 | inline Environment* env() const { return env_; } | |
| 23 | 23 | ||
| 24 | - // Completely stops the timer, making it no longer usable. | ||
| 25 | - void Stop(bool close = true); | ||
| 24 | + // Stop calling the timer callback. | ||
| 25 | + void Stop(); | ||
| 26 | + // Render the timer unusable and delete this object. | ||
| 27 | + void Close(); | ||
| 26 | 28 | ||
| 27 | 29 | // Starts / Restarts the Timer | |
| 28 | 30 | void Update(uint64_t interval, uint64_t repeat = 0); | |
| 29 | 31 | ||
| 30 | 32 | void Ref(); | |
| 31 | - | ||
| 32 | 33 | void Unref(); | |
| 33 | 34 | ||
| 34 | 35 | SET_NO_MEMORY_INFO(); | |
@@ -55,15 +56,15 @@ class TimerWrapHandle : public MemoryRetainer { | |||
| 55 | 56 | ||
| 56 | 57 | TimerWrapHandle(const TimerWrapHandle&) = delete; | |
| 57 | 58 | ||
| 58 | - ~TimerWrapHandle() { Stop(); } | ||
| 59 | + ~TimerWrapHandle() { Close(); } | ||
| 59 | 60 | ||
| 60 | 61 | void Update(uint64_t interval, uint64_t repeat = 0); | |
| 61 | 62 | ||
| 62 | 63 | void Ref(); | |
| 63 | - | ||
| 64 | 64 | void Unref(); | |
| 65 | 65 | ||
| 66 | - void Stop(bool close = true); | ||
| 66 | + void Stop(); | ||
| 67 | + void Close(); | ||
| 67 | 68 | ||
| 68 | 69 | void MemoryInfo(node::MemoryTracker* tracker) const override; | |
| 69 | 70 | ||
@@ -72,6 +73,7 @@ class TimerWrapHandle : public MemoryRetainer { | |||
| 72 | 73 | ||
| 73 | 74 | private: | |
| 74 | 75 | static void CleanupHook(void* data); | |
| 76 | + | ||
| 75 | 77 | TimerWrap* timer_; | |
| 76 | 78 | }; | |
| 77 | 79 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments