Skip to content

Commit

Permalink
Extract thread delay helper function.
Browse files Browse the repository at this point in the history
  • Loading branch information
kylc committed Mar 8, 2013
1 parent 81a54b0 commit ee559e8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/BitTorrent/Core.hs
Expand Up @@ -3,6 +3,7 @@ module BitTorrent.Core
) where

import Control.Concurrent
import Control.Concurrent.Delay
import Control.Monad
import Data.Maybe
import qualified Data.Map as Map
Expand Down Expand Up @@ -39,6 +40,6 @@ run f = do
Left e -> fail $ "Failed to parse bencode file: " ++ e

-- Download!
forever $ threadDelay $ 1000000 * 1 -- 1 second
forever $ delaySeconds 1

return ()
4 changes: 2 additions & 2 deletions src/BitTorrent/PeerManager.hs
Expand Up @@ -3,6 +3,7 @@ module BitTorrent.PeerManager
) where

import Control.Concurrent
import Control.Concurrent.Delay
import Control.Monad.State

import BitTorrent.Peer
Expand All @@ -17,5 +18,4 @@ runPeerMgr m ps = do
-- Loop until download finishes, computing interests
forever $ do
putStrLn "Tick"
threadDelay $ 1000000 * 1 -- 1 second

delaySeconds 1
8 changes: 8 additions & 0 deletions src/Control/Concurrent/Delay.hs
@@ -0,0 +1,8 @@
module Control.Concurrent.Delay
( delaySeconds
) where

import Control.Concurrent

delaySeconds :: Int -> IO ()
delaySeconds n = threadDelay $ 1000 * 1000 * n

0 comments on commit ee559e8

Please sign in to comment.