diff options
author | Sam Truzjan <pxqr.sta@gmail.com> | 2014-04-04 01:22:27 +0400 |
---|---|---|
committer | Sam Truzjan <pxqr.sta@gmail.com> | 2014-04-04 01:22:27 +0400 |
commit | 2a64b6b3e5766242d012baefde7bca54adc675f1 (patch) | |
tree | d92df65ddb60b6f9e923ed4fba69083aec021d21 /src/Network/BitTorrent/Client/Handle.hs | |
parent | c3e85d6baeba53168ed9dd2157f9b8f70bb1532d (diff) |
[Client] Use lifted concurrent operations
Diffstat (limited to 'src/Network/BitTorrent/Client/Handle.hs')
-rw-r--r-- | src/Network/BitTorrent/Client/Handle.hs | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/src/Network/BitTorrent/Client/Handle.hs b/src/Network/BitTorrent/Client/Handle.hs index 6e2dd0dc..2da3b357 100644 --- a/src/Network/BitTorrent/Client/Handle.hs +++ b/src/Network/BitTorrent/Client/Handle.hs | |||
@@ -19,7 +19,7 @@ module Network.BitTorrent.Client.Handle | |||
19 | ) where | 19 | ) where |
20 | 20 | ||
21 | import Control.Applicative | 21 | import Control.Applicative |
22 | import Control.Concurrent | 22 | import Control.Concurrent.Lifted as L |
23 | import Control.Monad | 23 | import Control.Monad |
24 | import Control.Monad.Trans | 24 | import Control.Monad.Trans |
25 | import Data.Default | 25 | import Data.Default |
@@ -40,28 +40,28 @@ import Network.BitTorrent.Tracker as Tracker | |||
40 | 40 | ||
41 | allocHandle :: InfoHash -> BitTorrent Handle -> BitTorrent Handle | 41 | allocHandle :: InfoHash -> BitTorrent Handle -> BitTorrent Handle |
42 | allocHandle ih m = do | 42 | allocHandle ih m = do |
43 | c @ Client {..} <- getClient | 43 | Client {..} <- getClient |
44 | liftIO $ modifyMVar clientTorrents $ \ handles -> do | 44 | modifyMVar clientTorrents $ \ handles -> do |
45 | case HM.lookup ih handles of | 45 | case HM.lookup ih handles of |
46 | Just h -> return (handles, h) | 46 | Just h -> return (handles, h) |
47 | Nothing -> do | 47 | Nothing -> do |
48 | h <- runBitTorrent c m | 48 | h <- m |
49 | return (HM.insert ih h handles, h) | 49 | return (HM.insert ih h handles, h) |
50 | 50 | ||
51 | freeHandle :: InfoHash -> BitTorrent () -> BitTorrent () | 51 | freeHandle :: InfoHash -> BitTorrent () -> BitTorrent () |
52 | freeHandle ih finalizer = do | 52 | freeHandle ih finalizer = do |
53 | c @ Client {..} <- getClient | 53 | c @ Client {..} <- getClient |
54 | liftIO $ modifyMVar_ clientTorrents $ \ handles -> do | 54 | modifyMVar_ clientTorrents $ \ handles -> do |
55 | case HM.lookup ih handles of | 55 | case HM.lookup ih handles of |
56 | Nothing -> return handles | 56 | Nothing -> return handles |
57 | Just _ -> do | 57 | Just _ -> do |
58 | runBitTorrent c finalizer | 58 | finalizer |
59 | return (HM.delete ih handles) | 59 | return (HM.delete ih handles) |
60 | 60 | ||
61 | lookupHandle :: InfoHash -> BitTorrent (Maybe Handle) | 61 | lookupHandle :: InfoHash -> BitTorrent (Maybe Handle) |
62 | lookupHandle ih = do | 62 | lookupHandle ih = do |
63 | Client {..} <- getClient | 63 | Client {..} <- getClient |
64 | handles <- liftIO $ readMVar clientTorrents | 64 | handles <- readMVar clientTorrents |
65 | return (HM.lookup ih handles) | 65 | return (HM.lookup ih handles) |
66 | 66 | ||
67 | {----------------------------------------------------------------------- | 67 | {----------------------------------------------------------------------- |