I want calculating hash of http post body and parsing it simultaneously when receiving, so I need a function like this:
unionSinks :: Monad m => Consumer a m r1 -> Consumer a m r2 -> Consumer a m (r1, r2)
unionSinks = ...
sinkBody :: Monad m => FromJSON v => Consumer ByteString m (Digest SHA1, v)
sinkBody = sinkHash `unionSinks` sinkParser json
When I developed image uploading I used passthroughSink in similar way. But I don't needed the result of conduit, which saves image to file, in this case.
Generally, I know how to implement fork using MVar-like things, but I don't sure that this is optimal solution.
Indeed you need ZipSink (or more general ZipConduit):
import Control.Applicative
import Data.Conduit
unionSinks :: (Monad m) => Sink a m r1 -> Sink a m r2 -> Sink a m (r1, r2)
unionSinks s1 s2 = getZipSink ((,) <$> ZipSink s1 <*> ZipSink s2)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With