Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reworking mkDebounce #996

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,17 @@ jobs:
- "--resolver lts-21 --stack-yaml stack-lts-21.yaml"
- "--resolver lts-20 --stack-yaml stack-lts-20.yaml"
- "--resolver lts-19 --stack-yaml stack-lts-19.yaml"
- "--resolver lts-18 --stack-yaml stack-lts-18.yaml"
exclude:
- os: "macos-latest"
args: "--resolver lts-19 --stack-yaml stack-lts-19.yaml"
- os: "macos-latest"
args: "--resolver lts-18 --stack-yaml stack-lts-18.yaml"

steps:
- name: Clone project
uses: actions/checkout@v4

# Not sure how to have GHC not setup twice
# Something with settings "ghc-version"?
# ["9.8", "9.6", "9.4", "9.2", "9.0", "8.10"]
# ["9.8", "9.6", "9.4", "9.2", "9.0"]
- uses: haskell-actions/setup@v2
name: Setup Haskell Stack
with:
Expand Down
22 changes: 16 additions & 6 deletions auto-update/ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# ChangeLog for auto-update

## 0.2.3

* [#996](https://github.com/yesodweb/wai/pull/996):
Refactored the `Control.Debounce` logic to not leak threads.
* [#996](https://github.com/yesodweb/wai/pull/996):
Added extra `DebounceEdge` options for different types of debouncing.
* `LeadingMute`: Action on first trigger, and ignore any triggers during cooldown
* `TrailingDelay`: First trigger starts cooldown, and
triggers during cooldown extend the cooldown. Action when cooldown expires.

## 0.2.2

* NewAPI: updateThreadName, reaperThreadName, debounceThreadName:
Expand All @@ -14,19 +24,19 @@

* Creating Reaper.Internal to export Reaper constructor.
* Hiding Reaper constructor.
* Add `reaperModify` to the `Reaper` API, allowing workload modification outside
* [#985](https://github.com/yesodweb/wai/pull/985):
Add `reaperModify` to the `Reaper` API, allowing workload modification outside
of the main `reaperAction` loop.
[#985](https://github.com/yesodweb/wai/pull/985)

## 0.1.6

* Add control of activation on leading vs. trailing edges for Control.Debounce
[#756](https://github.com/yesodweb/wai/pull/756)
* [#756](https://github.com/yesodweb/wai/pull/756):
Add control of activation on leading vs. trailing edges for Control.Debounce

## 0.1.5

* Using the Strict and StrictData language extensions for GHC >8.
[#752](https://github.com/yesodweb/wai/pull/752)
* [#752](https://github.com/yesodweb/wai/pull/752):
Using the Strict and StrictData language extensions for GHC >8.

## 0.1.4.1

Expand Down
5 changes: 5 additions & 0 deletions auto-update/Control/AutoUpdate.hs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ data UpdateSettings a = UpdateSettings
--
-- @since 0.1.0
, updateThreadName :: String
-- ^ Label of the thread being forked.
--
-- Default: @"AutoUpdate"@
--
-- @since 0.2.2
}

-- | Generate an action which will either read from an automatically
Expand Down
21 changes: 14 additions & 7 deletions auto-update/Control/Debounce.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,27 @@
--
-- @since 0.1.2
module Control.Debounce (
-- * Type
-- * Creation
mkDebounce,

-- * Settings
DI.DebounceSettings,
defaultDebounceSettings,

-- * Accessors
-- ** Accessors
DI.debounceFreq,
DI.debounceAction,
DI.debounceEdge,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder why DebounceEdge is NOT exported while deboundeEdge is exported.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never mind.
leadingEdge should be used instead of Leading.

DI.debounceThreadName,

-- ** Edge types
DI.leadingEdge,
DI.leadingMuteEdge,
DI.trailingEdge,

-- * Creation
mkDebounce,
DI.trailingDelayEdge,
) where

import Control.Concurrent (newEmptyMVar, threadDelay)
import Control.Concurrent (newMVar, threadDelay)
import qualified Control.Debounce.Internal as DI

-- | Default value for creating a 'DebounceSettings'.
Expand All @@ -56,8 +60,11 @@ defaultDebounceSettings =

-- | Generate an action which will trigger the debounced action to be performed.
--
-- /N.B. The generated action will always immediately return, regardless of the 'debounceFreq',/
-- /as the debounced action (and the delay\/cooldown) is always performed in a separate thread./
--
-- @since 0.1.2
mkDebounce :: DI.DebounceSettings -> IO (IO ())
mkDebounce settings = do
baton <- newEmptyMVar
baton <- newMVar ()
DI.mkDebounceInternal baton threadDelay settings
Loading