Павел Гаврилов | 18 Jul 15:15 2014
Picon

Conduit & state

Hi!

I have:

runUnixServer (serverSettings socket) $ \appData ->
  appSource appData
  $$ CL.map handleBS
  =$ appSink appData

I  want to store some data in priority queue in Monad.State and be able to access it inside the handleBS (now: handleBS :: ByteString -> ByteString). Can you send me on the right path?

Thanx, Pavel.


_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
Toby Goodwin | 18 Jul 16:07 2014

Re: Conduit & state

Hi Pavel,

>runUnixServer (serverSettings socket) $ \appData ->
> ...
>I  want to store some data in priority queue in Monad.State and be able to
>access it inside the handleBS (now: handleBS :: ByteString -> ByteString).

Funnily enough, I've just been looking at an analogous problem (with
runTCPClient and Persistent).

It seems that in the recent move from conduit-network to conduit-extra, the
run*Client and run*Server functions were specialized to the IO
monad. I don't know what the motivation for this change was (simpler
error messages perhaps?) but it does seem unhelpful.

The workaround I deployed last night was to roll my own runTCPClient'
which merges the code from the (deprecated) conduit-network package and
the (current) streaming-commons, but this is hardly satisfactory. I'm
sure I must be missing something.

(I don't know if there's a better list to discuss conduit.)

Toby.
Michael Snoyman | 20 Jul 00:08 2014

Re: Conduit & state

Keep in mind that a State monad won't necessarily play nicely with a multithreaded server. In particular, each new connection will have its state set at the point the state was at when the server started, and modifications from each child thread will be discarded. (That's assuming you do something like using monad-control.) Depending on your actual needs, you may instead want to store the priority queue in some kind of a mutable variable, so that the child threads are able to update the state for other threads.


On Fri, Jul 18, 2014 at 4:15 PM, Павел Гаврилов <lghtfck <at> gmail.com> wrote:
Hi!

I have:

runUnixServer (serverSettings socket) $ \appData ->
  appSource appData
  $$ CL.map handleBS
  =$ appSink appData

I  want to store some data in priority queue in Monad.State and be able to access it inside the handleBS (now: handleBS :: ByteString -> ByteString). Can you send me on the right path?

Thanx, Pavel.



_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Gmane