refactor ref change watching

Added to change notification to P2P protocol.

Switched to a TBChan so that a single long-running thread can be
started, and serve perhaps intermittent requests for change
notifications, without buffering all changes in memory.

The P2P runner currently starts up a new thread each times it waits
for a change, but that should allow later reusing a thread. Although
each connection from a peer will still need a new watcher thread to run.

The dependency on stm-chans is more or less free; some stuff in yesod
uses it, so it was already indirectly pulled in when building with the
webapp.

This commit was sponsored by Francois Marier on Patreon.
This commit is contained in:
Joey Hess 2016-12-09 14:52:38 -04:00
parent 596e1685a6
commit e152c322f8
No known key found for this signature in database
GPG key ID: C910D9222512E3C7
9 changed files with 142 additions and 53 deletions

View file

@ -16,6 +16,7 @@ module P2P.Annex
import Annex.Common
import Annex.Content
import Annex.Transfer
import Annex.ChangedRefs
import P2P.Protocol
import P2P.IO
import Logs.Location
@ -114,6 +115,14 @@ runLocal runmode runner a = case a of
protoaction False
next
Right _ -> runner next
WaitRefChange next -> do
v <- tryNonAsync $ bracket
watchChangedRefs
(liftIO . stopWatchingChangedRefs)
(liftIO . waitChangedRefs)
case v of
Left e -> return (Left (show e))
Right changedrefs -> runner (next changedrefs)
where
transfer mk k af ta = case runmode of
-- Update transfer logs when serving.