Hi I have a simple tcp server, and that server receives messages with specific length so basically i need to wait for TcpClient to fill buffer with that amount of data, and it works.
But I am not sure if this should look like it looks as I am writing this in f# and still learning:
let private WaitForData (client : TcpClient, dataLength : int) : Async<bool>=
async {
let mutable loopBreaker : bool = true
let mutable result : bool = false
while loopBreaker do
let isConnectionAlive : bool = IsConnectionEstablished client && client <> null
if isConnectionAlive && client.Available >= dataLength then
result <- true
loopBreaker <- false
if isConnectionAlive = false then
result <- false
loopBreaker <- false
Task.Delay(500)
|> Async.AwaitTask
|> ignore
return result
}
So as you see I use mutables to exit while loop and set result value, and have some if there.
Is this OK or maybe there is some more elegant way to write this