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 -> async { return 0 } |> Async.StartAsTask |> ignore
| _ ->
match (client.IsConnectionEstablished()) with
| true ->
incr frameNumber
DeployService.DeployCabninetService
let! messange = MessagingHandler.ReadMessage client
match(messange) with
| Some data ->
let frameNumber = uint32 frameNumber.Value
logger.Info(sprintf "Received message with Frame Number: %i" frameNumber)
| None ->
_logger.Info(sprintf "Client disconnected : %O" client.Client.RemoteEndPoint)
return! DisconnectClient client None
return! StartReading client
| false ->
_logger.Info(sprintf "Client disconnected : %O" client.Client.RemoteEndPoint)
return! DisconnectClient client None
}
StartReading client |> 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?