On Tue, Apr 1, 2014 at 1:35 PM, Pierre-Étienne Meunier <pierreetienne.meunier@gmail.com> wrote:
Is this the same as using “bracket accept hClose $ blabla” (modulo correct types)?

Sort of (and you could turn this pattern into a similar combinator), except here you want to accept the socket and hand it off to a child thread. In order to make that pattern safe you have to use mask:

    foo = mask $ \unmask -> do
        (s, a, _) <- unmask $ accept sock
        -- here async exceptions are blocked which gives you time to install a signal
        -- handler, you only unmask exceptions once the handler is installed
        forkIOWithUnmask $ \restore -> ((restore $ reply state s a) `catch` handler) `finally` (cleanup s a)

-- 
Gregory Collins <greg@gregorycollins.net>