F# Simple message reader using TCP I have a review request about this part of the code:

let private startReading (client:TcpClient) (bus:IBus) = 
    //TODO check if that can be changed to rec parameter
    let frameNumber = ref 0
    let rec StartReading (client:TcpClient) =
        async{
            match client with
            | null -&gt; async { return 0 } |&gt; Async.StartAsTask |&gt; ignore
            | _ -&gt;
                match (client.IsConnectionEstablished()) with
                | true -&gt;
                    incr frameNumber
                    DeployService.DeployCabninetService
                    let! messange = MessagingHandler.ReadMessage client

                    match(messange) with
                        | Some data -&gt; 
                            let frameNumber = uint32 frameNumber.Value
                            logger.Info(sprintf "Received message with Frame Number: %i" frameNumber) 

                        | None -&gt; 
                            _logger.Info(sprintf "Client disconnected : %O" client.Client.RemoteEndPoint)
                            return! DisconnectClient client None                                

                    return! StartReading client
                | false -&gt;
                    _logger.Info(sprintf "Client disconnected : %O" client.Client.RemoteEndPoint)
                    return! DisconnectClient client None
        }

    StartReading client |&gt; Async.StartAsTask


It is simple reading message procedure from tcp client in f#, but I feel this can be written more gracefully, especially todo part with frame number incrementation using ref in f# feels wrong. 

Any suggestions?
Why do you make this call Async.StartAsTask instead of just return the Async&lt;T&gt; to let the client handle that as needed?




  let rec StartReading (client:TcpClient) =


I would call it reader and then give it the signature of:

let rec reader frameNo (client:TcpClient) =


in order to get rid of reffor frameNumber.

You can then initially call it:

reader 0 client |&gt; Async.StartAsTask


and recursively:

return! reader (frameNo + 1) client