-
-
Notifications
You must be signed in to change notification settings - Fork 435
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
378 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
sentry-android-core/src/main/java/io/sentry/android/core/internal/util/Debouncer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package io.sentry.android.core.internal.util; | ||
|
||
import io.sentry.transport.ICurrentDateProvider; | ||
import org.jetbrains.annotations.ApiStatus; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
/** A simple time-based debouncing mechanism */ | ||
@ApiStatus.Internal | ||
public class Debouncer { | ||
|
||
private final long waitTimeMs; | ||
private final @NotNull ICurrentDateProvider timeProvider; | ||
|
||
private Long lastExecutionTime = null; | ||
|
||
public Debouncer(final @NotNull ICurrentDateProvider timeProvider, final long waitTimeMs) { | ||
this.timeProvider = timeProvider; | ||
this.waitTimeMs = waitTimeMs; | ||
} | ||
|
||
/** | ||
* @return true if the execution should be debounced due to the last execution being within within | ||
* waitTimeMs, otherwise false. | ||
*/ | ||
public boolean checkForDebounce() { | ||
final long now = timeProvider.getCurrentTimeMillis(); | ||
if (lastExecutionTime == null || (lastExecutionTime + waitTimeMs) <= now) { | ||
lastExecutionTime = now; | ||
return false; | ||
} | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.