You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pulsar.apache.org by GitBox <gi...@apache.org> on 2021/08/10 09:47:24 UTC

[GitHub] [pulsar-dotpulsar] PetterIsberg commented on a change in pull request #85: Add a watchdog to the connections

PetterIsberg commented on a change in pull request #85:
URL: https://github.com/apache/pulsar-dotpulsar/pull/85#discussion_r685865186



##########
File path: src/DotPulsar/Internal/Watchdog.cs
##########
@@ -0,0 +1,61 @@
+namespace DotPulsar.Internal
+{
+    using System;
+    using System.Collections.Generic;
+    using System.Text;
+    using System.Threading;
+
+    public class Watchdog: IDisposable
+    {
+        private CancellationTokenSource _cancellationTokenSource;
+        private readonly TimeSpan _timeout;
+        private readonly Timer _timer;
+
+        public Watchdog(TimeSpan timeout)
+        {
+            _timeout = timeout;
+            _timer = new Timer(OnTimeout);
+            _cancellationTokenSource = new CancellationTokenSource();
+        }
+
+        public CancellationToken CancellationToken
+        {
+            get => _cancellationTokenSource.Token;
+        }
+
+        public void GotMessage()
+        {
+            ResetTimer();
+        }
+
+        public void Enable()
+        {
+            if (_cancellationTokenSource.IsCancellationRequested)
+                _cancellationTokenSource = new CancellationTokenSource();
+            ResetTimer();
+        }
+
+        public void Disable()
+        {
+            _timer.Change(Timeout.InfiniteTimeSpan, Timeout.InfiniteTimeSpan);

Review comment:
       > If dueTime is Timeout.Infinite, the callback method is never invoked; the timer is disabled, but can be re-enabled by calling Change and specifying a positive value for dueTime.
   
   This is disabling the timer without disposing it.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org