From 8e502da42cbc0bb1db3f0fdc9493ded7ef95f77b Mon Sep 17 00:00:00 2001 From: Wesley Kerfoot Date: Sat, 30 Mar 2019 23:38:05 -0400 Subject: [PATCH] Use async-pool in order to limit rate limiting --- pullwatch.cabal | 6 +++--- src/PullWatch/PullWatch.hs | 6 +++--- stack.yaml | 1 + 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/pullwatch.cabal b/pullwatch.cabal index d837b4e..c6168ce 100644 --- a/pullwatch.cabal +++ b/pullwatch.cabal @@ -40,7 +40,7 @@ library , text , bytestring , vector - , async + , async-pool >= 0.9.0 , containers , yaml , system-filepath @@ -65,7 +65,7 @@ executable pullwatch-exe , text , bytestring , vector - , async + , async-pool >= 0.9.0 , containers , yaml , system-filepath @@ -91,7 +91,7 @@ test-suite pullwatch-test , text , bytestring , vector - , async + , async-pool >= 0.9.0 , containers , yaml , data-default diff --git a/src/PullWatch/PullWatch.hs b/src/PullWatch/PullWatch.hs index e2c0f41..6ed92a8 100644 --- a/src/PullWatch/PullWatch.hs +++ b/src/PullWatch/PullWatch.hs @@ -21,7 +21,7 @@ import GitHub.Data.PullRequests import Control.Applicative import Control.Concurrent (threadDelay) -import Control.Concurrent.Async +import Control.Concurrent.Async.Pool import DBus.Notify import Data.Maybe import Data.Vector ((!?)) @@ -95,8 +95,8 @@ getLatestPRs :: (?pat :: (Maybe Auth.Auth)) => [Repo] -> IO (Maybe PullRequests) -getLatestPRs repos = do - prs <- mapConcurrently getLatest repos +getLatestPRs repos = withTaskGroup 2 $ \g -> do + prs <- mapConcurrently g getLatest repos return $ maybesToMap prs monitorPRs :: (?pat :: (Maybe Auth.Auth)) => diff --git a/stack.yaml b/stack.yaml index 792cb09..ad6d287 100644 --- a/stack.yaml +++ b/stack.yaml @@ -41,6 +41,7 @@ packages: extra-deps: - fdo-notify-0.3.1 - github-0.21 + - async-pool-0.9.0 - git: git@github.com:sbergot/ArgParser.git commit: 801ffac4551382a0b08a50ae3b98402ebbf35b30