listener :: MVar (IRCMessage -> IO ()) -> TChan IRCMessage -> IO ()
listener mvar chan = do
    sender <- takeMVar mvar
    serve "127.0.0.1" "27315" $ \sock _ -> mask $ \restore -> do
        bcast <- atomically $ dupTChan chan
        tid <- forkIO $ restore $ do
            runEffect $
                fromSocket sock >->
                receiveIRCMessages >->
                (forever $ await >>= liftIO . sender)
        flip finally (killThread tid) $ restore $ forever $ do
            next_msg <- atomically $ readTChan bcast
            send sock (encode next_msg)
listener :: MVar (IRCMessage -> IO ()) -> TChan IRCMessage -> IO ()
listener mvar chan = do
    sender <- takeMVar mvar
    serve "127.0.0.1" "27315" $ \sock _ -> mask $ \restore -> do
        bcast <- atomically $ dupTChan chan
        tid <- forkIO $ restore $ do
            runEffect $
                fromSocket sock >->
                receiveIRCMessages >->
                (forever $ await >>= liftIO . sender)
        flip finally (killThread tid) $ restore $ forever $ do
            next_msg <- atomically $ readTChan bcast
            send sock (encode next_msg)
listener mvar chan = do
    sender <- takeMVar mvar
    serve "127.0.0.1" "27315" $ \sock _ -> mask $ \restore -> do
        bcast <- atomically $ dupTChan chan
        tid <- forkIO $ restore $ do
            runEffect $
                fromSocket sock >->
                receiveIRCMessages >->
                (forever $ await >>= liftIO . sender)
        flip finally (killThread tid) $ restore $ forever $ do
            next_msg <- atomically $ readTChan bcast
            send sock (encode next_msg)