├── Assets
├── icon.png
├── debounce_marble.png
└── icon.svg
├── Directory.Build.props
├── DebounceMonitoring
├── Ref.cs
├── DebounceMonitoring.csproj
├── ObjectTimeStamps.cs
├── ObservableDebounceDecorator.cs
├── ObservableDebounceExtensions.cs
└── DebounceMonitor.cs
├── DebounceMonitoring.Tests
├── Models.cs
├── DebounceMonitoring.Tests.csproj
├── ObservableDebounceTest.cs
├── IntervalTest.cs
├── Snippets
│ └── Sample.cs
└── DebounceHereTest.cs
├── LICENSE
├── .github
└── workflows
│ └── ci.yml
├── DebounceMonitoring.sln
├── .gitattributes
├── README.md
└── .gitignore
/Assets/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SIDOVSKY/DebounceMonitoring/HEAD/Assets/icon.png
--------------------------------------------------------------------------------
/Assets/debounce_marble.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SIDOVSKY/DebounceMonitoring/HEAD/Assets/debounce_marble.png
--------------------------------------------------------------------------------
/Directory.Build.props:
--------------------------------------------------------------------------------
1 |
2 |
3 | enable
4 | 9.0
5 |
6 |
--------------------------------------------------------------------------------
/DebounceMonitoring/Ref.cs:
--------------------------------------------------------------------------------
1 | namespace DebounceMonitoring
2 | {
3 | internal class Ref where T : struct
4 | {
5 | public T Value;
6 |
7 | public Ref(T value = default)
8 | {
9 | Value = value;
10 | }
11 |
12 | public override string ToString() => Value.ToString();
13 | }
14 | }
--------------------------------------------------------------------------------
/DebounceMonitoring.Tests/Models.cs:
--------------------------------------------------------------------------------
1 | namespace DebounceMonitoring.Tests
2 | {
3 | public class DebouncingSample
4 | {
5 | public static bool DebounceDuring100msStatic()
6 | {
7 | return DebounceMonitor.DebounceHereStatic(100);
8 | }
9 |
10 | public bool DebounceDuring100ms()
11 | {
12 | return this.DebounceHere(100);
13 | }
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/DebounceMonitoring.Tests/DebounceMonitoring.Tests.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net5.0
5 | false
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/DebounceMonitoring/DebounceMonitoring.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netstandard2.0
5 | true
6 | SIDOVSKY
7 | MIT
8 | https://github.com/SIDOVSKY/DebounceMonitoring
9 | https://github.com/SIDOVSKY/DebounceMonitoring.git
10 | git
11 | Vadim Sedov
12 | icon.png
13 | debounce, throttle, click, touch, ui
14 | 1.0.1
15 | 📑 Add debounce logic for any method in a single line.
16 | Thread-safety improvements
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/DebounceMonitoring.Tests/ObservableDebounceTest.cs:
--------------------------------------------------------------------------------
1 | using System.Reactive.Linq;
2 | using System.Threading.Tasks;
3 | using Xunit;
4 |
5 | namespace DebounceMonitoring.Tests
6 | {
7 | public class ObservableDebounceTest
8 | {
9 | [Fact]
10 | public async void Interval_Should_Not_Slide_With_Each_Call()
11 | {
12 | Assert.Equal(
13 | new[] { 0, 110, 220 },
14 | await Observable.Create(async o =>
15 | {
16 | o.OnNext(0);
17 | await Task.Delay(50);
18 | o.OnNext(50); // too fast
19 | await Task.Delay(60);
20 | o.OnNext(110); // 50 + 60 > 100, OK
21 | await Task.Delay(50);
22 | o.OnNext(160);
23 | await Task.Delay(60);
24 | o.OnNext(220);
25 | })
26 | .Debounce(intervalMs: 100)
27 | .ToList());
28 | }
29 | }
30 | }
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2021 Vadim Sedov
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
--------------------------------------------------------------------------------
/.github/workflows/ci.yml:
--------------------------------------------------------------------------------
1 | name: CI
2 |
3 | on:
4 | push:
5 | branches:
6 | - master
7 | paths-ignore:
8 | - '**/*.md'
9 | pull_request:
10 | paths-ignore:
11 | - '**/*.md'
12 |
13 | jobs:
14 | main:
15 | name: Build, Test
16 | runs-on: ubuntu-latest
17 | steps:
18 | - name: Checkout code
19 | uses: actions/checkout@v2
20 |
21 | - name: Test
22 | id: unit-test
23 | run: |
24 | dotnet test --logger "trx;LogFileName=UnitTestResults.trx"
25 |
26 | - name: Prepare Unit Test Results
27 | id: prepare-unit-test-results
28 | if: ${{ !cancelled() && (steps.unit-test.outcome == 'success' || steps.unit-test.outcome == 'failure') }}
29 | run: |
30 | dotnet tool install --global trx2junit
31 | trx2junit ./DebounceMonitoring.Tests/TestResults/UnitTestResults.trx
32 |
33 | - name: Publish Unit Test Results
34 | if: ${{ !cancelled() && steps.prepare-unit-test-results.outcome == 'success' }}
35 | uses: docker://ghcr.io/enricomi/publish-unit-test-result-action:v1.9
36 | with:
37 | github_token: ${{ github.token }}
38 | files: ./DebounceMonitoring.Tests/TestResults/UnitTestResults.xml
39 | check_name: Unit Test Results
40 | comment_on_pr: false
--------------------------------------------------------------------------------
/DebounceMonitoring/ObjectTimeStamps.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Runtime.CompilerServices;
3 |
4 | namespace DebounceMonitoring
5 | {
6 | internal class ObjectTimeStamps
7 | {
8 | private readonly object _lock = new();
9 | private ConditionalWeakTable