{"action":"created","issue":{"url":"https://api.github.com/repos/hreinhardt/amqp/issues/59","labels_url":"https://api.github.com/repos/hreinhardt/amqp/issues/59/labels{/name}","comments_url":"https://api.github.com/repos/hreinhardt/amqp/issues/59/comments","events_url":"https://api.github.com/repos/hreinhardt/amqp/issues/59/events","html_url":"https://github.com/hreinhardt/amqp/issues/59","id":119469616,"number":59,"title":"consumeMsgs forever","user":{"login":"mschristiansen","id":437005,"avatar_url":"https://avatars.githubusercontent.com/u/437005?v=3","gravatar_id":"","url":"https://api.github.com/users/mschristiansen","html_url":"https://github.com/mschristiansen","followers_url":"https://api.github.com/users/mschristiansen/followers","following_url":"https://api.github.com/users/mschristiansen/following{/other_user}","gists_url":"https://api.github.com/users/mschristiansen/gists{/gist_id}","starred_url":"https://api.github.com/users/mschristiansen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mschristiansen/subscriptions","organizations_url":"https://api.github.com/users/mschristiansen/orgs","repos_url":"https://api.github.com/users/mschristiansen/repos","events_url":"https://api.github.com/users/mschristiansen/events{/privacy}","received_events_url":"https://api.github.com/users/mschristiansen/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2015-11-30T11:02:57Z","updated_at":"2015-11-30T15:16:15Z","closed_at":"2015-11-30T15:16:14Z","body":"In a long running service what is the correct way to wait for the consumeMsgs function?\r\n\r\nThe examples in the documentation is using `getLine` or `threadDelay` and for my application I haven't found a better way than using `forever $ threadDelay 1000000`, but it seems a bit of a hack.\r\n\r\nMight be something obvious in the use of `Control.Concurrency` that I'm missing.\r\n\r\n```\r\nwithChannel :: Connection -> (Channel -> IO a) -> IO a\r\nwithChannel conn =\r\n  bracket (openChannel conn) closeChannel\r\n\r\nconsumeMaterials :: Config -> Connection -> (Material -> IO ()) -> IO ()\r\nconsumeMaterials (Config {..}) conn f =\r\n  withChannel conn $ \\chan -> do\r\n    void $ declareQueue chan newQueue { queueName = cfgMqQueue }\r\n    void $ consumeMsgs chan cfgMqQueue Ack (upsertMessage f)\r\n    forever $ threadDelay 1000000\r\n\r\nupsertMessage :: (Material -> IO ()) -> (Message, Envelope) -> IO ()\r\nupsertMessage f (msg, env) = do\r\n  logStr $ \"upsertMessage: \" ++ show msg\r\n  void $ f $ fromMessage msg\r\n  ackEnv env\r\n```"},"comment":{"url":"https://api.github.com/repos/hreinhardt/amqp/issues/comments/160657871","html_url":"https://github.com/hreinhardt/amqp/issues/59#issuecomment-160657871","issue_url":"https://api.github.com/repos/hreinhardt/amqp/issues/59","id":160657871,"user":{"login":"mschristiansen","id":437005,"avatar_url":"https://avatars.githubusercontent.com/u/437005?v=3","gravatar_id":"","url":"https://api.github.com/users/mschristiansen","html_url":"https://github.com/mschristiansen","followers_url":"https://api.github.com/users/mschristiansen/followers","following_url":"https://api.github.com/users/mschristiansen/following{/other_user}","gists_url":"https://api.github.com/users/mschristiansen/gists{/gist_id}","starred_url":"https://api.github.com/users/mschristiansen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mschristiansen/subscriptions","organizations_url":"https://api.github.com/users/mschristiansen/orgs","repos_url":"https://api.github.com/users/mschristiansen/repos","events_url":"https://api.github.com/users/mschristiansen/events{/privacy}","received_events_url":"https://api.github.com/users/mschristiansen/received_events","type":"User","site_admin":false},"created_at":"2015-11-30T15:16:14Z","updated_at":"2015-11-30T15:16:14Z","body":"I'll stick with `threadDelay`. Thanks for your response!"}}