diff options
author | joe <joe@jerkface.net> | 2017-07-14 16:39:36 -0400 |
---|---|---|
committer | joe <joe@jerkface.net> | 2017-07-14 16:40:18 -0400 |
commit | 31d72c02c1bd3574042ac3b67eb4d28d87d187df (patch) | |
tree | 3131505b8fe73f8c96909a269de9376ef55892b2 /src/Network/QueryResponse.hs | |
parent | 4171673e85049ce1647c669f2fd83652621510eb (diff) |
Transport modifier utility: onInbound.
Diffstat (limited to 'src/Network/QueryResponse.hs')
-rw-r--r-- | src/Network/QueryResponse.hs | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/Network/QueryResponse.hs b/src/Network/QueryResponse.hs index 9262132f..5083a87c 100644 --- a/src/Network/QueryResponse.hs +++ b/src/Network/QueryResponse.hs | |||
@@ -191,6 +191,16 @@ layerTransport parse encode tr = | |||
191 | sendMessage tr addr msg | 191 | sendMessage tr addr msg |
192 | } | 192 | } |
193 | 193 | ||
194 | -- | Modify a 'Transport' to invoke an action upon every received packet. | ||
195 | onInbound :: (addr -> x -> IO ()) -> Transport err addr x -> Transport err addr x | ||
196 | onInbound f tr = tr | ||
197 | { awaitMessage = do | ||
198 | m <- awaitMessage tr | ||
199 | case m of | ||
200 | Just (Right (x, addr)) -> f addr x | ||
201 | Nothing -> return () | ||
202 | return m | ||
203 | } | ||
194 | 204 | ||
195 | -- | To dipatch responses to our outbound queries, we require three primitives. | 205 | -- | To dipatch responses to our outbound queries, we require three primitives. |
196 | -- See the 'transactionMethods' function to create these primitives out of a | 206 | -- See the 'transactionMethods' function to create these primitives out of a |