send notifications when the TransferQueue is changed

The fun part was making it move things from TransferQueue to currentTransfers
entirely atomically. Which will avoid inconsistent display if the WebApp
renders the current status at just the wrong time. STM to the rescue!
This commit is contained in:
Joey Hess 2012-07-28 18:47:24 -04:00
parent 3cc1885793
commit e31277d38a
5 changed files with 67 additions and 32 deletions

View file

@ -34,12 +34,18 @@ transfererThread :: ThreadState -> DaemonStatusHandle -> TransferQueue -> Transf
transfererThread st dstatus transferqueue slots = go
where
go = do
(t, info) <- getNextTransfer transferqueue
(t, info) <- getNextTransfer transferqueue dstatus
ifM (runThreadState st $ shouldTransfer dstatus t info)
( do
debug thisThread [ "Transferring:" , show t ]
notifyDaemonStatusChange dstatus
transferThread st dstatus slots t info
, debug thisThread [ "Skipping unnecessary transfer:" , show t ]
, do
debug thisThread [ "Skipping unnecessary transfer:" , show t ]
-- getNextTransfer added t to the
-- daemonstatus's transfer map.
void $ removeTransfer dstatus t
notifyDaemonStatusChange dstatus
)
go