-
Notifications
You must be signed in to change notification settings - Fork 127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generalized Constraints #87
Comments
If the monad only appears in positive position (the result), then I'm not sure about your specific case. Typically a queue like this would be orthogonal to conduit usage, and due to the half-duplex nature of conduit. |
Oh nice - that worked out: -- Each call of 'runRedis' takes a network connection from the 'Connection'
-- pool and runs the given 'Redis' action. Calls to 'runRedis' may thus block
-- while all connections from the pool are in use.
-runRedis :: Connection -> Redis a -> IO a
+runRedis :: MonadIO m => Connection -> Redis a -> m a
runRedis (Conn pool) redis =
- withResource pool $ \conn -> runRedisInternal conn redis
+ liftIO $ withResource pool $ \conn -> runRedisInternal conn redis With the current types I don't have the ability to compose conduit behavior directly from / to the redis instance. Instead of the above sourceBus :: MonadIO m => Connection -> [ByteString] -> Source m (ByteString, ByteString)
sourceBus = ???
sinkBus :: MonadIO m => Connection -> Sink (ByteString, ByteString) m ()
sinkBus = ??? And then be able to compose conduit behavior from these. Instead, I've had to use the above described functions where I pass in a queue, and then compose conduits in another thread that drains from the queue. |
I doubt this change will give you what you want, given that it could have
already been done in your code by adding in a liftIO call.
…On Fri, Feb 17, 2017, 7:39 AM Mark Fine ***@***.***> wrote:
Oh nice - that worked out:
-- Each call of 'runRedis' takes a network connection from the 'Connection'
-- pool and runs the given 'Redis' action. Calls to 'runRedis' may thus block
-- while all connections from the pool are in use.-runRedis :: Connection -> Redis a -> IO a
+runRedis :: MonadIO m => Connection -> Redis a -> m a
runRedis (Conn pool) redis =
- withResource pool $ \conn -> runRedisInternal conn redis+ liftIO $ withResource pool $ \conn -> runRedisInternal conn redis
With the current types I don't have the ability to compose conduit
behavior directly from / to the redis instance. Instead of the above
sinkBus and sourceBus which take queues, I would love to be able to have:
sourceBus :: MonadIO m => Connection -> [ByteString] -> Source m (ByteString, ByteString)
sourceBus = ???
sinkBus :: MonadIO m => Connection -> Sink (ByteString, ByteString) m ()
sinkBus = ???
And then be able to compose conduit behavior from these. Instead, I've had
to use the above described functions where I pass in a queue, and then
compose conduits in another thread that drains from the queue.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#87 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AADBB4baTvtINMB5v1NAQ0gZHTrTqqsAks5rdTJ3gaJpZM4MDs3g>
.
|
Right. I can get the sink to work if I move the sinkBus :: MonadIO m => Connection -> Sink (ByteString, ByteString) m ()
sinkBus conn =
CL.mapM_ $ uncurry $ \channel message ->
liftIO $ runRedis conn $
void $ publish channel message Which is ok, though I would have like to have maintained the connection. But for the source, it seems like I'm totally out of luck: sourceBus :: MonadIO m => Connection -> [ByteString] -> Sink (ByteString, ByteString) m ()
sourceBus conn topics =
liftIO $ runRedis conn $
pubSub (psubscribe topics) $ \msg -> do
yield (msgChannel msg, msgMessage msg)
return mempty Which yields me:
|
The concrete
IO
types in hedis make it very hard to use with other kinds of Monads, especially in applications using Monad transformers. How do you feel about making more generalized types available? For example:In my particular application, I'm extremely interested in building Conduit Producers/Sources around
pubSub
and Consumers/Sinks aroundpublish
. With the currentIO
types, I've had to introduce a and thread queue for sourcing from / sinking to redis with hedis instead of a having more general Producers/Sources and Consumers/Sinks:In particular, having to introduce a thread and queue for reading from / writing to redis is particularly onerous in my application with significant thread counts already :(
/cc @snoyberg in case I'm misunderstanding the limitations here around conduits. I'm happy to help with generalizing the types if that's desirable. Thanks for the great library!
The text was updated successfully, but these errors were encountered: