runWebSocketsWith' :: Protocol p
                   => WebSocketsOptions
                   -> p
                   -> WebSockets p a
                   -> Iteratee ByteString IO ()
                   -> Iteratee ByteString IO a
runWebSocketsWith' opts proto ws outIter = do
    -- Create sink with a random source
    let sinkIter = encodeMessages proto =$ builderToByteString =$ outIter
    sink <- Sink <$> liftIO (newMVar sinkIter)

    let sender = makeBuilderSender outIter
        env    = WebSocketsEnv opts sender sink proto
        iter   = runReaderT (unWebSockets ws) env

    decodeMessages proto =$ iter
runWebSocketsWith' :: Protocol p
                   => WebSocketsOptions
                   -> p
                   -> WebSockets p a
                   -> Iteratee ByteString IO ()
                   -> Iteratee ByteString IO a
runWebSocketsWith' opts proto ws outIter = do
    -- Create sink with a random source
    let sinkIter = encodeMessages proto =$ builderToByteString =$ outIter
    sink <- Sink <$> liftIO (newMVar sinkIter)

    let sender = makeBuilderSender outIter
        env    = WebSocketsEnv opts sender sink proto
        iter   = runReaderT (unWebSockets ws) env

    decodeMessages proto =$ iter
runWebSocketsWith' opts proto ws outIter = do
    -- Create sink with a random source
    let sinkIter = encodeMessages proto =$ builderToByteString =$ outIter
    sink <- Sink <$> liftIO (newMVar sinkIter)

    let sender = makeBuilderSender outIter
        env    = WebSocketsEnv opts sender sink proto
        iter   = runReaderT (unWebSockets ws) env

    decodeMessages proto =$ iter