{"action":"created","comment":{"url":"https://api.github.com/repos/alephcloud/hs-aws-kinesis-client/pulls/comments/27231190","id":27231190,"diff_hunk":"@@ -354,111 +318,101 @@ generatePartitionKey gen =\n   Kin.partitionKey (T.pack name)\n     & either (error ∘ T.unpack) id\n \n--- | This will take up to @n@ items from a 'TBMQueue'.\n+-- | This will take up to @n@ items from a 'TBMQueue', with a timeout.\n --\n-takeTBMQueue\n-  ∷ Int\n+takeTBMQueueWithTimeout\n+  ∷ ∀ α\n+  . Int -- ^ number of items to get\n+  → Int -- ^ timeout in microseconds\n   → TBMQueue α\n-  → STM [α]\n-takeTBMQueue n q\n-  | n <= 0 = return []\n-  | otherwise = do\n-      res ← tryReadTBMQueue q\n-      case res of\n-        Just (Just x) → (x:) <$> takeTBMQueue (n - 1) q\n-        _ → return []\n+  → IO [α]\n+takeTBMQueueWithTimeout n timeout q = do\n+  timedOutVar ← newEmptyTMVarIO\n+\n+  let\n+    timeoutAction = do\n+      threadDelay timeout\n+      atomically $ putTMVar timedOutVar ()\n+\n+    go xs\n+      | length xs ≥ n = return xs\n+      | otherwise = do\n+          res ← Left <$> readTBMQueue q <|> Right <$> readTMVar timedOutVar\n+          case res of\n+            Left mx → maybe (return xs) (go ∘ (:xs)) mx\n+            Right () → return xs\n+\n+  withAsync timeoutAction $ \\h → do\n+    xs ← atomically $ go []\n+    xs <$ cancel h\n \n -- | A policy for chunking the contents of the message queue.\n --\n data ChunkingPolicy\n   = ChunkingPolicy\n-  { _cpMaxChunkSize ∷ Int\n+  { _cpMaxChunkSize ∷ !Int\n   -- ^ The largest chunk size that is permitted.\n \n-  , _cpThrottlingDelay ∷ Int\n-  -- ^ The time after which a chunk should be committed, even if the maximum\n-  -- chunk size has not yet been reached.\n+  , _cpMinChunkingInterval ∷ !Int\n+  -- ^ The time in microseconds after which a chunk should be committed, even\n+  -- if the maximum chunk size has not yet been reached.\n   }\n \n -- | A 'Source' that reads chunks off a bounded STM queue according some\n -- 'ChunkingPolicy'.\n --\n chunkedSourceTBMQueue\n-  ∷ ( MonadIO m\n-    , MonadBaseControl IO m\n-    )\n-  ⇒ ChunkingPolicy\n+  ∷ ChunkingPolicy\n   → TBMQueue α\n-  → Source m [α]\n-chunkedSourceTBMQueue bp@ChunkingPolicy{..} q = do\n-  terminateNow ← liftIO ∘ atomically $ isClosedTBMQueue q\n-  unless terminateNow $ do\n-    items ← liftIO ∘ atomically $ takeTBMQueue _cpMaxChunkSize q\n+  → Source IO [α]\n+chunkedSourceTBMQueue cp@ChunkingPolicy{..} q = do\n+  shouldTerminate ←\n+    liftIO ∘ atomically $\n+      (&&) <$> isClosedTBMQueue q <*> isEmptyTBMQueue q\n+\n+  unless shouldTerminate $ do\n+    items ← lift $ takeTBMQueueWithTimeout _cpMaxChunkSize _cpMinChunkingInterval q","path":"src/Aws/Kinesis/Client/Producer.hs","position":248,"original_position":253,"commit_id":"ccc73b2b85cd2a277d5b6bc254222fc42e94fc51","original_commit_id":"c74db90e6ca81380e0351cfb9c37c7cda7c219cc","user":{"login":"jonsterling","id":55057,"avatar_url":"https://avatars.githubusercontent.com/u/55057?v=3","gravatar_id":"","url":"https://api.github.com/users/jonsterling","html_url":"https://github.com/jonsterling","followers_url":"https://api.github.com/users/jonsterling/followers","following_url":"https://api.github.com/users/jonsterling/following{/other_user}","gists_url":"https://api.github.com/users/jonsterling/gists{/gist_id}","starred_url":"https://api.github.com/users/jonsterling/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jonsterling/subscriptions","organizations_url":"https://api.github.com/users/jonsterling/orgs","repos_url":"https://api.github.com/users/jonsterling/repos","events_url":"https://api.github.com/users/jonsterling/events{/privacy}","received_events_url":"https://api.github.com/users/jonsterling/received_events","type":"User","site_admin":false},"body":"Very interesting, thank you for clarifying this. I'll play around with your suggestions and see if I can come up with something that works nicely in the sense you describe.","created_at":"2015-03-26T16:45:20Z","updated_at":"2015-03-26T16:45:20Z","html_url":"https://github.com/alephcloud/hs-aws-kinesis-client/pull/20#discussion_r27231190","pull_request_url":"https://api.github.com/repos/alephcloud/hs-aws-kinesis-client/pulls/20","_links":{"self":{"href":"https://api.github.com/repos/alephcloud/hs-aws-kinesis-client/pulls/comments/27231190"},"html":{"href":"https://github.com/alephcloud/hs-aws-kinesis-client/pull/20#discussion_r27231190"},"pull_request":{"href":"https://api.github.com/repos/alephcloud/hs-aws-kinesis-client/pulls/20"}}},"pull_request":{"url":"https://api.github.com/repos/alephcloud/hs-aws-kinesis-client/pulls/20","id":31784739,"html_url":"https://github.com/alephcloud/hs-aws-kinesis-client/pull/20","diff_url":"https://github.com/alephcloud/hs-aws-kinesis-client/pull/20.diff","patch_url":"https://github.com/alephcloud/hs-aws-kinesis-client/pull/20.patch","issue_url":"https://api.github.com/repos/alephcloud/hs-aws-kinesis-client/issues/20","number":20,"state":"open","locked":false,"title":"Breaking changes: improved shutdown and error approach","user":{"login":"jonsterling","id":55057,"avatar_url":"https://avatars.githubusercontent.com/u/55057?v=3","gravatar_id":"","url":"https://api.github.com/users/jonsterling","html_url":"https://github.com/jonsterling","followers_url":"https://api.github.com/users/jonsterling/followers","following_url":"https://api.github.com/users/jonsterling/following{/other_user}","gists_url":"https://api.github.com/users/jonsterling/gists{/gist_id}","starred_url":"https://api.github.com/users/jonsterling/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jonsterling/subscriptions","organizations_url":"https://api.github.com/users/jonsterling/orgs","repos_url":"https://api.github.com/users/jonsterling/repos","events_url":"https://api.github.com/users/jonsterling/events{/privacy}","received_events_url":"https://api.github.com/users/jonsterling/received_events","type":"User","site_admin":false},"body":"This is intended to address #19 and #17\r\n\r\nThere is more to be done before this may be merged.\r\n\r\n- [x] stop plumbing exceptions into `MonadError`\r\n- [x] remove `either` dependency\r\n- [x] expose possibly-throwing functions as returning `m (Either e a)`\r\n- [x] use `enclosed-exceptions` where appropriate\r\n- [x] implement graceful shutdown of producer \r\n- [x] add configurable timeout for producer worker cleanup\r\n- [x] update changelog","created_at":"2015-03-23T23:34:26Z","updated_at":"2015-03-26T16:45:20Z","closed_at":null,"merged_at":null,"merge_commit_sha":"8557511765b9dac017e6da4e53277ba387e24094","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/alephcloud/hs-aws-kinesis-client/pulls/20/commits","review_comments_url":"https://api.github.com/repos/alephcloud/hs-aws-kinesis-client/pulls/20/comments","review_comment_url":"https://api.github.com/repos/alephcloud/hs-aws-kinesis-client/pulls/comments{/number}","comments_url":"https://api.github.com/repos/alephcloud/hs-aws-kinesis-client/issues/20/comments","statuses_url":"https://api.github.com/repos/alephcloud/hs-aws-kinesis-client/statuses/ccc73b2b85cd2a277d5b6bc254222fc42e94fc51","head":{"label":"alephcloud:js/errors-and-shutdown","ref":"js/errors-and-shutdown","sha":"ccc73b2b85cd2a277d5b6bc254222fc42e94fc51","user":{"login":"alephcloud","id":1145376,"avatar_url":"https://avatars.githubusercontent.com/u/1145376?v=3","gravatar_id":"","url":"https://api.github.com/users/alephcloud","html_url":"https://github.com/alephcloud","followers_url":"https://api.github.com/users/alephcloud/followers","following_url":"https://api.github.com/users/alephcloud/following{/other_user}","gists_url":"https://api.github.com/users/alephcloud/gists{/gist_id}","starred_url":"https://api.github.com/users/alephcloud/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alephcloud/subscriptions","organizations_url":"https://api.github.com/users/alephcloud/orgs","repos_url":"https://api.github.com/users/alephcloud/repos","events_url":"https://api.github.com/users/alephcloud/events{/privacy}","received_events_url":"https://api.github.com/users/alephcloud/received_events","type":"Organization","site_admin":false},"repo":{"id":28429911,"name":"hs-aws-kinesis-client","full_name":"alephcloud/hs-aws-kinesis-client","owner":{"login":"alephcloud","id":1145376,"avatar_url":"https://avatars.githubusercontent.com/u/1145376?v=3","gravatar_id":"","url":"https://api.github.com/users/alephcloud","html_url":"https://github.com/alephcloud","followers_url":"https://api.github.com/users/alephcloud/followers","following_url":"https://api.github.com/users/alephcloud/following{/other_user}","gists_url":"https://api.github.com/users/alephcloud/gists{/gist_id}","starred_url":"https://api.github.com/users/alephcloud/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alephcloud/subscriptions","organizations_url":"https://api.github.com/users/alephcloud/orgs","repos_url":"https://api.github.com/users/alephcloud/repos","events_url":"https://api.github.com/users/alephcloud/events{/privacy}","received_events_url":"https://api.github.com/users/alephcloud/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/alephcloud/hs-aws-kinesis-client","description":"A producer/consumer client library for Kinesis","fork":false,"url":"https://api.github.com/repos/alephcloud/hs-aws-kinesis-client","forks_url":"https://api.github.com/repos/alephcloud/hs-aws-kinesis-client/forks","keys_url":"https://api.github.com/repos/alephcloud/hs-aws-kinesis-client/keys{/key_id}","collaborators_url":"https://api.github.com/repos/alephcloud/hs-aws-kinesis-client/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/alephcloud/hs-aws-kinesis-client/teams","hooks_url":"https://api.github.com/repos/alephcloud/hs-aws-kinesis-client/hooks","issue_events_url":"https://api.github.com/repos/alephcloud/hs-aws-kinesis-client/issues/events{/number}","events_url":"https://api.github.com/repos/alephcloud/hs-aws-kinesis-client/events","assignees_url":"https://api.github.com/repos/alephcloud/hs-aws-kinesis-client/assignees{/user}","branches_url":"https://api.github.com/repos/alephcloud/hs-aws-kinesis-client/branches{/branch}","tags_url":"https://api.github.com/repos/alephcloud/hs-aws-kinesis-client/tags","blobs_url":"https://api.github.com/repos/alephcloud/hs-aws-kinesis-client/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/alephcloud/hs-aws-kinesis-client/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/alephcloud/hs-aws-kinesis-client/git/refs{/sha}","trees_url":"https://api.github.com/repos/alephcloud/hs-aws-kinesis-client/git/trees{/sha}","statuses_url":"https://api.github.com/repos/alephcloud/hs-aws-kinesis-client/statuses/{sha}","languages_url":"https://api.github.com/repos/alephcloud/hs-aws-kinesis-client/languages","stargazers_url":"https://api.github.com/repos/alephcloud/hs-aws-kinesis-client/stargazers","contributors_url":"https://api.github.com/repos/alephcloud/hs-aws-kinesis-client/contributors","subscribers_url":"https://api.github.com/repos/alephcloud/hs-aws-kinesis-client/subscribers","subscription_url":"https://api.github.com/repos/alephcloud/hs-aws-kinesis-client/subscription","commits_url":"https://api.github.com/repos/alephcloud/hs-aws-kinesis-client/commits{/sha}","git_commits_url":"https://api.github.com/repos/alephcloud/hs-aws-kinesis-client/git/commits{/sha}","comments_url":"https://api.github.com/repos/alephcloud/hs-aws-kinesis-client/comments{/number}","issue_comment_url":"https://api.github.com/repos/alephcloud/hs-aws-kinesis-client/issues/comments{/number}","contents_url":"https://api.github.com/repos/alephcloud/hs-aws-kinesis-client/contents/{+path}","compare_url":"https://api.github.com/repos/alephcloud/hs-aws-kinesis-client/compare/{base}...{head}","merges_url":"https://api.github.com/repos/alephcloud/hs-aws-kinesis-client/merges","archive_url":"https://api.github.com/repos/alephcloud/hs-aws-kinesis-client/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/alephcloud/hs-aws-kinesis-client/downloads","issues_url":"https://api.github.com/repos/alephcloud/hs-aws-kinesis-client/issues{/number}","pulls_url":"https://api.github.com/repos/alephcloud/hs-aws-kinesis-client/pulls{/number}","milestones_url":"https://api.github.com/repos/alephcloud/hs-aws-kinesis-client/milestones{/number}","notifications_url":"https://api.github.com/repos/alephcloud/hs-aws-kinesis-client/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/alephcloud/hs-aws-kinesis-client/labels{/name}","releases_url":"https://api.github.com/repos/alephcloud/hs-aws-kinesis-client/releases{/id}","created_at":"2014-12-24T02:16:36Z","updated_at":"2015-03-20T20:16:51Z","pushed_at":"2015-03-25T22:59:13Z","git_url":"git://github.com/alephcloud/hs-aws-kinesis-client.git","ssh_url":"git@github.com:alephcloud/hs-aws-kinesis-client.git","clone_url":"https://github.com/alephcloud/hs-aws-kinesis-client.git","svn_url":"https://github.com/alephcloud/hs-aws-kinesis-client","homepage":"http://hackage.haskell.org/package/aws-kinesis-client","size":678,"stargazers_count":1,"watchers_count":1,"language":"Haskell","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":5,"forks":0,"open_issues":5,"watchers":1,"default_branch":"master"}},"base":{"label":"alephcloud:master","ref":"master","sha":"d292fc8b1c6dad4ac00e0d50afb1bc4b7418938f","user":{"login":"alephcloud","id":1145376,"avatar_url":"https://avatars.githubusercontent.com/u/1145376?v=3","gravatar_id":"","url":"https://api.github.com/users/alephcloud","html_url":"https://github.com/alephcloud","followers_url":"https://api.github.com/users/alephcloud/followers","following_url":"https://api.github.com/users/alephcloud/following{/other_user}","gists_url":"https://api.github.com/users/alephcloud/gists{/gist_id}","starred_url":"https://api.github.com/users/alephcloud/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alephcloud/subscriptions","organizations_url":"https://api.github.com/users/alephcloud/orgs","repos_url":"https://api.github.com/users/alephcloud/repos","events_url":"https://api.github.com/users/alephcloud/events{/privacy}","received_events_url":"https://api.github.com/users/alephcloud/received_events","type":"Organization","site_admin":false},"repo":{"id":28429911,"name":"hs-aws-kinesis-client","full_name":"alephcloud/hs-aws-kinesis-client","owner":{"login":"alephcloud","id":1145376,"avatar_url":"https://avatars.githubusercontent.com/u/1145376?v=3","gravatar_id":"","url":"https://api.github.com/users/alephcloud","html_url":"https://github.com/alephcloud","followers_url":"https://api.github.com/users/alephcloud/followers","following_url":"https://api.github.com/users/alephcloud/following{/other_user}","gists_url":"https://api.github.com/users/alephcloud/gists{/gist_id}","starred_url":"https://api.github.com/users/alephcloud/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alephcloud/subscriptions","organizations_url":"https://api.github.com/users/alephcloud/orgs","repos_url":"https://api.github.com/users/alephcloud/repos","events_url":"https://api.github.com/users/alephcloud/events{/privacy}","received_events_url":"https://api.github.com/users/alephcloud/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/alephcloud/hs-aws-kinesis-client","description":"A producer/consumer client library for Kinesis","fork":false,"url":"https://api.github.com/repos/alephcloud/hs-aws-kinesis-client","forks_url":"https://api.github.com/repos/alephcloud/hs-aws-kinesis-client/forks","keys_url":"https://api.github.com/repos/alephcloud/hs-aws-kinesis-client/keys{/key_id}","collaborators_url":"https://api.github.com/repos/alephcloud/hs-aws-kinesis-client/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/alephcloud/hs-aws-kinesis-client/teams","hooks_url":"https://api.github.com/repos/alephcloud/hs-aws-kinesis-client/hooks","issue_events_url":"https://api.github.com/repos/alephcloud/hs-aws-kinesis-client/issues/events{/number}","events_url":"https://api.github.com/repos/alephcloud/hs-aws-kinesis-client/events","assignees_url":"https://api.github.com/repos/alephcloud/hs-aws-kinesis-client/assignees{/user}","branches_url":"https://api.github.com/repos/alephcloud/hs-aws-kinesis-client/branches{/branch}","tags_url":"https://api.github.com/repos/alephcloud/hs-aws-kinesis-client/tags","blobs_url":"https://api.github.com/repos/alephcloud/hs-aws-kinesis-client/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/alephcloud/hs-aws-kinesis-client/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/alephcloud/hs-aws-kinesis-client/git/refs{/sha}","trees_url":"https://api.github.com/repos/alephcloud/hs-aws-kinesis-client/git/trees{/sha}","statuses_url":"https://api.github.com/repos/alephcloud/hs-aws-kinesis-client/statuses/{sha}","languages_url":"https://api.github.com/repos/alephcloud/hs-aws-kinesis-client/languages","stargazers_url":"https://api.github.com/repos/alephcloud/hs-aws-kinesis-client/stargazers","contributors_url":"https://api.github.com/repos/alephcloud/hs-aws-kinesis-client/contributors","subscribers_url":"https://api.github.com/repos/alephcloud/hs-aws-kinesis-client/subscribers","subscription_url":"https://api.github.com/repos/alephcloud/hs-aws-kinesis-client/subscription","commits_url":"https://api.github.com/repos/alephcloud/hs-aws-kinesis-client/commits{/sha}","git_commits_url":"https://api.github.com/repos/alephcloud/hs-aws-kinesis-client/git/commits{/sha}","comments_url":"https://api.github.com/repos/alephcloud/hs-aws-kinesis-client/comments{/number}","issue_comment_url":"https://api.github.com/repos/alephcloud/hs-aws-kinesis-client/issues/comments{/number}","contents_url":"https://api.github.com/repos/alephcloud/hs-aws-kinesis-client/contents/{+path}","compare_url":"https://api.github.com/repos/alephcloud/hs-aws-kinesis-client/compare/{base}...{head}","merges_url":"https://api.github.com/repos/alephcloud/hs-aws-kinesis-client/merges","archive_url":"https://api.github.com/repos/alephcloud/hs-aws-kinesis-client/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/alephcloud/hs-aws-kinesis-client/downloads","issues_url":"https://api.github.com/repos/alephcloud/hs-aws-kinesis-client/issues{/number}","pulls_url":"https://api.github.com/repos/alephcloud/hs-aws-kinesis-client/pulls{/number}","milestones_url":"https://api.github.com/repos/alephcloud/hs-aws-kinesis-client/milestones{/number}","notifications_url":"https://api.github.com/repos/alephcloud/hs-aws-kinesis-client/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/alephcloud/hs-aws-kinesis-client/labels{/name}","releases_url":"https://api.github.com/repos/alephcloud/hs-aws-kinesis-client/releases{/id}","created_at":"2014-12-24T02:16:36Z","updated_at":"2015-03-20T20:16:51Z","pushed_at":"2015-03-25T22:59:13Z","git_url":"git://github.com/alephcloud/hs-aws-kinesis-client.git","ssh_url":"git@github.com:alephcloud/hs-aws-kinesis-client.git","clone_url":"https://github.com/alephcloud/hs-aws-kinesis-client.git","svn_url":"https://github.com/alephcloud/hs-aws-kinesis-client","homepage":"http://hackage.haskell.org/package/aws-kinesis-client","size":678,"stargazers_count":1,"watchers_count":1,"language":"Haskell","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":5,"forks":0,"open_issues":5,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/alephcloud/hs-aws-kinesis-client/pulls/20"},"html":{"href":"https://github.com/alephcloud/hs-aws-kinesis-client/pull/20"},"issue":{"href":"https://api.github.com/repos/alephcloud/hs-aws-kinesis-client/issues/20"},"comments":{"href":"https://api.github.com/repos/alephcloud/hs-aws-kinesis-client/issues/20/comments"},"review_comments":{"href":"https://api.github.com/repos/alephcloud/hs-aws-kinesis-client/pulls/20/comments"},"review_comment":{"href":"https://api.github.com/repos/alephcloud/hs-aws-kinesis-client/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/alephcloud/hs-aws-kinesis-client/pulls/20/commits"},"statuses":{"href":"https://api.github.com/repos/alephcloud/hs-aws-kinesis-client/statuses/ccc73b2b85cd2a277d5b6bc254222fc42e94fc51"}}}}