{"action":"created","issue":{"url":"https://api.github.com/repos/bos/pool/issues/21","repository_url":"https://api.github.com/repos/bos/pool","labels_url":"https://api.github.com/repos/bos/pool/issues/21/labels{/name}","comments_url":"https://api.github.com/repos/bos/pool/issues/21/comments","events_url":"https://api.github.com/repos/bos/pool/issues/21/events","html_url":"https://github.com/bos/pool/pull/21","id":48624187,"number":21,"title":"Event-driven reaper","user":{"login":"DaveCTurner","id":5058284,"avatar_url":"https://avatars.githubusercontent.com/u/5058284?v=3","gravatar_id":"","url":"https://api.github.com/users/DaveCTurner","html_url":"https://github.com/DaveCTurner","followers_url":"https://api.github.com/users/DaveCTurner/followers","following_url":"https://api.github.com/users/DaveCTurner/following{/other_user}","gists_url":"https://api.github.com/users/DaveCTurner/gists{/gist_id}","starred_url":"https://api.github.com/users/DaveCTurner/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DaveCTurner/subscriptions","organizations_url":"https://api.github.com/users/DaveCTurner/orgs","repos_url":"https://api.github.com/users/DaveCTurner/repos","events_url":"https://api.github.com/users/DaveCTurner/events{/privacy}","received_events_url":"https://api.github.com/users/DaveCTurner/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2014-11-13T11:11:23Z","updated_at":"2016-07-05T09:51:05Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/bos/pool/pulls/21","html_url":"https://github.com/bos/pool/pull/21","diff_url":"https://github.com/bos/pool/pull/21.diff","patch_url":"https://github.com/bos/pool/pull/21.patch"},"body":"Hi,\r\n\r\nI'd like to use the resource-pool package, but the polling model for the reaper doesn't work well with what I'm trying to do. Running the reaper every second is too frequent, but simply decreasing the polling frequency means that stale resources will hang around for too long.\r\n\r\nI've made an event-driven reaper in the past as part of another project and it worked well before, and I've now extracted this basic functionality into the [alarmclock](http://hackage.haskell.org/package/alarmclock) package.\r\n\r\nWould you consider a change to resource-pool to make it use this event-driven model rather than the current polling one? I will prepare a pull request if so.\r\n\r\nI'm willing to believe that `alarmclock` is not suitable in its current form, or has some subtle bug or performance issue, so if you have comments for how it could be improved then I'd be glad to hear them.\r\n\r\nCheers,\r\n"},"comment":{"url":"https://api.github.com/repos/bos/pool/issues/comments/230435366","html_url":"https://github.com/bos/pool/pull/21#issuecomment-230435366","issue_url":"https://api.github.com/repos/bos/pool/issues/21","id":230435366,"user":{"login":"basvandijk","id":576355,"avatar_url":"https://avatars.githubusercontent.com/u/576355?v=3","gravatar_id":"","url":"https://api.github.com/users/basvandijk","html_url":"https://github.com/basvandijk","followers_url":"https://api.github.com/users/basvandijk/followers","following_url":"https://api.github.com/users/basvandijk/following{/other_user}","gists_url":"https://api.github.com/users/basvandijk/gists{/gist_id}","starred_url":"https://api.github.com/users/basvandijk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/basvandijk/subscriptions","organizations_url":"https://api.github.com/users/basvandijk/orgs","repos_url":"https://api.github.com/users/basvandijk/repos","events_url":"https://api.github.com/users/basvandijk/events{/privacy}","received_events_url":"https://api.github.com/users/basvandijk/received_events","type":"User","site_admin":false},"created_at":"2016-07-05T09:51:05Z","updated_at":"2016-07-05T09:51:05Z","body":"I think I should be maintaining pool but unfortunately I don't have much time to spend on it these days. Maybe @bos can be convinced to also make @DaveCTurner a maintainer.\r\n\r\nI did review the PR and except for the following it looks good to me:\r\n\r\nIn the `alarmclock` package there looks to be the possibility for a deadlock in [newAlarmClock'](https://bitbucket.org/davecturner/alarmclock/src/6ed54cf2cfa5fd30760aab845c1cdd5808c4b924/src/Control/Concurrent/AlarmClock.hs?at=default&fileviewer=file-view-default#AlarmClock.hs-103). If an exception gets raised in the forked thread before the finaliser gets registered the `joinVar`will never be put anymore and then the `readMVar` will deadlock. A better version would mask asynchronous exceptions before forking: \r\n\r\n```haskell\r\nnewAlarmClock' :: TimeScale t => (AlarmClock t -> t -> IO ()) -> IO (AlarmClock t)\r\nnewAlarmClock' onWakeUp = do\r\n  joinVar <- newEmptyMVar\r\n  ac <- atomically $ AlarmClock (readMVar joinVar) <$> newTVar AlarmNotSet <*> newTVar False\r\n  void $ mask $ \\restore -> forkIO $ restore (runAlarmClock ac (onWakeUp ac)) \r\n                                       `finally` putMVar joinVar ()\r\n  return ac\r\n```\r\n\r\nAn even better alternative is to use either the [async](http://hackage.haskell.org/package/async) or [threads](http://hackage.haskell.org/package/threads) package."}}
{"actor":{"display_login":"basvandijk"}}