downloader :: PeerThread -> IO ()
downloader (PeerThread _ _ requestChan dataChan) = do
    putStrLn "Draining reader"
    requests <- getChanContents requestChan
    mapM_ download requests
  where
    download :: Integer -> IO ()
    download x = do
        -- [todo] - Replace with real download implementation
        -- | Download a piece and write to writer channel
        putStrLn $ "Download block " ++ show x
        threadDelay 1000000
        writeChan dataChan $ Block x "hello world"

-- [todo] - Close the channel on shutdown.
--
-- The writer might be down and the channel will keep accepting more data,
-- leading to ugly hard to track down bugs.
--
-- | Called by bracket before the writer is shutdown
downloader :: PeerThread -> IO ()
downloader (PeerThread _ _ requestChan dataChan) = do
    putStrLn "Draining reader"
    requests <- getChanContents requestChan
    mapM_ download requests
  where
    download :: Integer -> IO ()
    download x = do
        -- [todo] - Replace with real download implementation
        -- | Download a piece and write to writer channel
        putStrLn $ "Download block " ++ show x
        threadDelay 1000000
        writeChan dataChan $ Block x "hello world"

-- [todo] - Close the channel on shutdown.
--
-- The writer might be down and the channel will keep accepting more data,
-- leading to ugly hard to track down bugs.
--
-- | Called by bracket before the writer is shutdown
downloader (PeerThread _ _ requestChan dataChan) = do
    putStrLn "Draining reader"
    requests <- getChanContents requestChan
    mapM_ download requests
  where
    download :: Integer -> IO ()
    download x = do
        -- [todo] - Replace with real download implementation
        -- | Download a piece and write to writer channel
        putStrLn $ "Download block " ++ show x
        threadDelay 1000000
        writeChan dataChan $ Block x "hello world"

-- [todo] - Close the channel on shutdown.
--
-- The writer might be down and the channel will keep accepting more data,
-- leading to ugly hard to track down bugs.
--
-- | Called by bracket before the writer is shutdown