Beispiel #1
0
        public void should_hold_the_call_while_paused()
        {
            var counter          = new Counter();
            var debounceFunction = new Debouncer(counter.Hit, TimeSpan.FromMilliseconds(50));

            debounceFunction.Pause();

            debounceFunction.Execute();
            debounceFunction.Execute();

            Thread.Sleep(100);

            counter.Count.Should().Be(0);

            debounceFunction.Execute();
            debounceFunction.Execute();

            Thread.Sleep(100);

            counter.Count.Should().Be(0);

            debounceFunction.Resume();

            Thread.Sleep(20);

            counter.Count.Should().Be(0);

            Thread.Sleep(100);

            counter.Count.Should().Be(1);
        }
        public async Task ActionsAreDebounced()
        {
            var executionCounter = 0;

            var debouncer = new Debouncer(TimeSpan.FromSeconds(.1));

            debouncer.Execute(() => executionCounter++);
            debouncer.Execute(() => executionCounter++);
            debouncer.Execute(() => executionCounter++);

            await Task.Delay(TimeSpan.FromSeconds(.5));

            Assert.Equal(1, executionCounter);
        }
Beispiel #3
0
        public void should_hold_the_call_for_debounce_duration()
        {
            var counter          = new Counter();
            var debounceFunction = new Debouncer(counter.Hit, TimeSpan.FromMilliseconds(50));

            debounceFunction.Execute();
            debounceFunction.Execute();
            debounceFunction.Execute();

            counter.Count.Should().Be(0);

            Thread.Sleep(100);

            counter.Count.Should().Be(1);
        }
 private void OnFileChanged(object source, FileSystemEventArgs e)
 {
     if (!_disposed)
     {
         _debouncer?.Execute(Reload);
     }
 }
        private void Watcher_Error(object sender, ErrorEventArgs e)
        {
            var ex = e.GetException();
            var dw = (FileSystemWatcher)sender;

            if (ex.GetType() == typeof(InternalBufferOverflowException))
            {
                _logger.Warn(ex, "The file system watcher experienced an internal buffer overflow for: {0}", dw.Path);

                _changedPaths.TryAdd(dw.Path, dw.Path);
                _scanDebouncer.Execute();
            }
            else
            {
                _logger.Error(ex, "Error in Directory watcher for: {0}" + dw.Path);

                DisposeWatcher(dw, true);
            }
        }
Beispiel #6
0
        public void should_wait_for_last_call_if_execute_resets_timer()
        {
            var counter          = new Counter();
            var debounceFunction = new Debouncer(counter.Hit, TimeSpan.FromMilliseconds(200), true);

            debounceFunction.Execute();

            Thread.Sleep(100);

            debounceFunction.Execute();

            Thread.Sleep(150);

            counter.Count.Should().Be(0);

            Thread.Sleep(100);

            counter.Count.Should().Be(1);
        }
Beispiel #7
0
 public void Handle(CommandUpdatedEvent message)
 {
     if (message.Command.Body.SendUpdatesToClient)
     {
         lock (_pendingUpdates)
         {
             _pendingUpdates[message.Command.Id] = message.Command.ToResource();
         }
         _debouncer.Execute();
     }
 }
        public async Task OnlyLastActionIsInvoked()
        {
            string?invokedAction = null;

            var debouncer = new Debouncer(TimeSpan.FromSeconds(.1));

            foreach (var action in new[] { "a", "b", "c" })
            {
                debouncer.Execute(() => invokedAction = action);
            }

            await Task.Delay(TimeSpan.FromSeconds(.5));

            Assert.NotNull(invokedAction);
            Assert.Equal("c", invokedAction);
        }
Beispiel #9
0
        public void should_throttle_calls()
        {
            var counter          = new Counter();
            var debounceFunction = new Debouncer(counter.Hit, TimeSpan.FromMilliseconds(50));

            debounceFunction.Execute();
            debounceFunction.Execute();
            debounceFunction.Execute();

            counter.Count.Should().Be(0);

            Thread.Sleep(200);

            debounceFunction.Execute();
            debounceFunction.Execute();
            debounceFunction.Execute();

            Thread.Sleep(200);

            counter.Count.Should().Be(2);
        }
Beispiel #10
0
 public void Handle(QueueUpdatedEvent message)
 {
     _broadcastDebounce.Execute();
 }
 public void Handle(EpisodeGrabbedEvent message)
 {
     _refreshDebounce.Execute();
 }
 public void Handle(AlbumGrabbedEvent message)
 {
     _refreshDebounce.Execute();
 }