diff options
author | Joey Hess <joey@kitenet.net> | 2012-07-02 16:07:39 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2012-07-02 16:07:39 -0400 |
commit | ad0b82795742228d3ed9eab7e50f4000f6d78734 (patch) | |
tree | a6789a1b7df865a18ea5469e1f9a054a5e7f87e4 /Assistant/TransferQueue.hs | |
parent | c9d7e9f6bd5adac8a5ff0e925bbac549f962cdb0 (diff) |
added
Diffstat (limited to 'Assistant/TransferQueue.hs')
-rw-r--r-- | Assistant/TransferQueue.hs | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/Assistant/TransferQueue.hs b/Assistant/TransferQueue.hs new file mode 100644 index 000000000..979cbb80f --- /dev/null +++ b/Assistant/TransferQueue.hs @@ -0,0 +1,43 @@ +{- git-annex assistant pending transfer queue + - + - Copyright 2012 Joey Hess <joey@kitenet.net> + - + - Licensed under the GNU GPL version 3 or higher. + -} + +module Assistant.TransferQueue where + +import Common.Annex +import Utility.TSet +import Logs.Transfer +import Types.Remote + +import Control.Concurrent.STM + +type TransferQueue = TChan (Transfer, TransferInfo) + +newTransferQueue :: IO TransferQueue +newTransferQueue = atomically newTChan + +stubInfo :: AssociatedFile -> TransferInfo +stubInfo f = TransferInfo + { startedTime = Nothing + , transferPid = Nothing + , transferThread = Nothing + , bytesComplete = Nothing + , associatedFile = f + } + +{- Adds a pending transfer to the end of the queue. -} +queueTransfer :: TransferQueue -> Transfer -> AssociatedFile -> IO () +queueTransfer q transfer f = void $ atomically $ + writeTChan q (transfer, stubInfo f) + +{- Adds a pending transfer to the start of the queue, to be processed next. -} +queueNextTransfer :: TransferQueue -> Transfer -> AssociatedFile -> IO () +queueNextTransfer q transfer f = void $ atomically $ + unGetTChan q (transfer, stubInfo f) + +{- Blocks until a pending transfer is available in the queue. -} +getNextTransfer :: TransferQueue -> IO (Transfer, TransferInfo) +getNextTransfer = atomically . readTChan |