It seems you are using asyncGetInput and asyncGetReponse to introduce concurrency, although this is a noble goal it is kind of useless because you are only using those from other workflows which are already running in the thread pool anyway. In that case it would be ok to make a synchronous call from inside those workflows.
The second point is about the do! at the end of asyncPrintResponse, you should use return! in your recursive call otherwise you will get a memory leak. I'm not sure if we can call this a bug because it can probably be considered normal that the definition of Do in the workflow isn't built for that. I've personally been corrected for that same error here: http://stackoverflow.com/questions/6905251/f-async-difference-between-two-structure https://stackoverflow.com/questions/6905251/f-async-difference-between-two-structure
[edit] There's a difference between handling concurrency and introducing concurrency. If we ignore your code for a moment, you have two distinct inherently sequential workflows that you can parallelize and asyncSendInput and asyncPrintResponse is already doing that by itself, as such asyncGetInput and asyncGetResponse are unnecessary and will only create more lightweight thread that will end up being scheduled/deschedule from the thread pool.
Here's a little cleanup:
open System
open System.Net.Sockets
let rec asyncSendInput (stream : NetworkStream) =
async {
let input = Console.Read() |> BitConverter.GetBytes
input |> Array.iter stream.WriteByte
return! asyncSendInput stream
}
let rec asyncPrintResponse (stream : NetworkStream) =
async {
let response = stream.ReadByte() |> Char.ConvertFromUtf32
Console.Write(response)
return! asyncPrintResponse stream
}
[<EntryPoint>]
let main args =
let client = new System.Net.Sockets.TcpClient()
client.Connect(args.[0], Int32.Parse(args.[1]))
printfn "Connected to %A %A..." args.[0] args.[1]
let stream = client.GetStream()
printfn "Got stream, starting two way asynchronous communication."
asyncSendInput stream |> Async.Start
asyncPrintResponse stream |> Async.RunSynchronously
0
It seems you are using asyncGetInput and asyncGetReponse to introduce concurrency, although this is a noble goal it is kind of useless because you are only using those from other workflows which are already running in the thread pool anyway. In that case it would be ok to make a synchronous call from inside those workflows.
The second point is about the do! at the end of asyncPrintResponse, you should use return! in your recursive call otherwise you will get a memory leak. I'm not sure if we can call this a bug because it can probably be considered normal that the definition of Do in the workflow isn't built for that. I've personally been corrected for that same error here: http://stackoverflow.com/questions/6905251/f-async-difference-between-two-structure
[edit] There's a difference between handling concurrency and introducing concurrency. If we ignore your code for a moment, you have two distinct inherently sequential workflows that you can parallelize and asyncSendInput and asyncPrintResponse is already doing that by itself, as such asyncGetInput and asyncGetResponse are unnecessary and will only create more lightweight thread that will end up being scheduled/deschedule from the thread pool.
Here's a little cleanup:
open System
open System.Net.Sockets
let rec asyncSendInput (stream : NetworkStream) =
async {
let input = Console.Read() |> BitConverter.GetBytes
input |> Array.iter stream.WriteByte
return! asyncSendInput stream
}
let rec asyncPrintResponse (stream : NetworkStream) =
async {
let response = stream.ReadByte() |> Char.ConvertFromUtf32
Console.Write(response)
return! asyncPrintResponse stream
}
[<EntryPoint>]
let main args =
let client = new System.Net.Sockets.TcpClient()
client.Connect(args.[0], Int32.Parse(args.[1]))
printfn "Connected to %A %A..." args.[0] args.[1]
let stream = client.GetStream()
printfn "Got stream, starting two way asynchronous communication."
asyncSendInput stream |> Async.Start
asyncPrintResponse stream |> Async.RunSynchronously
0
It seems you are using asyncGetInput and asyncGetReponse to introduce concurrency, although this is a noble goal it is kind of useless because you are only using those from other workflows which are already running in the thread pool anyway. In that case it would be ok to make a synchronous call from inside those workflows.
The second point is about the do! at the end of asyncPrintResponse, you should use return! in your recursive call otherwise you will get a memory leak. I'm not sure if we can call this a bug because it can probably be considered normal that the definition of Do in the workflow isn't built for that. I've personally been corrected for that same error here: https://stackoverflow.com/questions/6905251/f-async-difference-between-two-structure
[edit] There's a difference between handling concurrency and introducing concurrency. If we ignore your code for a moment, you have two distinct inherently sequential workflows that you can parallelize and asyncSendInput and asyncPrintResponse is already doing that by itself, as such asyncGetInput and asyncGetResponse are unnecessary and will only create more lightweight thread that will end up being scheduled/deschedule from the thread pool.
Here's a little cleanup:
open System
open System.Net.Sockets
let rec asyncSendInput (stream : NetworkStream) =
async {
let input = Console.Read() |> BitConverter.GetBytes
input |> Array.iter stream.WriteByte
return! asyncSendInput stream
}
let rec asyncPrintResponse (stream : NetworkStream) =
async {
let response = stream.ReadByte() |> Char.ConvertFromUtf32
Console.Write(response)
return! asyncPrintResponse stream
}
[<EntryPoint>]
let main args =
let client = new System.Net.Sockets.TcpClient()
client.Connect(args.[0], Int32.Parse(args.[1]))
printfn "Connected to %A %A..." args.[0] args.[1]
let stream = client.GetStream()
printfn "Got stream, starting two way asynchronous communication."
asyncSendInput stream |> Async.Start
asyncPrintResponse stream |> Async.RunSynchronously
0
It seems you are using asyncGetInput and asyncGetReponse to introduce concurrency, although this is a noble goal it is kind of useless because you are only using those from other workflows which are already running in the thread pool anyway. In that case it would be ok to make a synchronous call from inside those workflows.
The second point is about the do! at the end of asyncPrintResponse, you should use return! in your recursive call otherwise you will get a memory leak. I'm not sure if we can call this a bug because it can probably be considered normal that the definition of Do in the workflow isn't built for that. I've personally been corrected for that same error here: http://stackoverflow.com/questions/6905251/f-async-difference-between-two-structure
[edit] There's a difference between handling concurrency and introducing concurrency. If we ignore your code for a moment, you have two distinct inherently sequential workflows that you can parallelize and asyncSendInput and asyncPrintResponse is already doing that by itself, as such asyncGetInput and asyncGetResponse are unnecessary and will only create more lightweight thread that will end up being scheduled/deschedule from the thread pool.
Here's a little cleanup:
open System
open System.Net.Sockets
let rec asyncSendInput (stream : NetworkStream) =
async {
let input = Console.Read() |> BitConverter.GetBytes
input |> Array.iter stream.WriteByte
return! asyncSendInput stream
}
let rec asyncPrintResponse (stream : NetworkStream) =
async {
let response = stream.ReadByte() |> Char.ConvertFromUtf32
Console.Write(response)
return! asyncPrintResponse stream
}
[<EntryPoint>]
let main args =
let client = new System.Net.Sockets.TcpClient()
client.Connect(args.[0], Int32.Parse(args.[1]))
printfn "Connected to %A %A..." args.[0] args.[1]
let stream = client.GetStream()
printfn "Got stream, starting two way asynchronous communication."
asyncSendInput stream |> Async.Start
asyncPrintResponse stream |> Async.RunSynchronously
0
It seems you are using asyncGetInput and asyncGetReponse to introduce concurrency, although this is a noble goal it is kind of useless because you are only using those from other workflows which are already running in the thread pool anyway. In that case it would be ok to make a synchronous call from inside those workflows.
The second point is about the do! at the end of asyncPrintResponse, you should use return! in your recursive call otherwise you will get a memory leak. I'm not sure if we can call this a bug because it can probably be considered normal that the definition of Do in the workflow isn't built for that. I've personally been corrected for that same error here: http://stackoverflow.com/questions/6905251/f-async-difference-between-two-structure
It seems you are using asyncGetInput and asyncGetReponse to introduce concurrency, although this is a noble goal it is kind of useless because you are only using those from other workflows which are already running in the thread pool anyway. In that case it would be ok to make a synchronous call from inside those workflows.
The second point is about the do! at the end of asyncPrintResponse, you should use return! in your recursive call otherwise you will get a memory leak. I'm not sure if we can call this a bug because it can probably be considered normal that the definition of Do in the workflow isn't built for that. I've personally been corrected for that same error here: http://stackoverflow.com/questions/6905251/f-async-difference-between-two-structure
[edit] There's a difference between handling concurrency and introducing concurrency. If we ignore your code for a moment, you have two distinct inherently sequential workflows that you can parallelize and asyncSendInput and asyncPrintResponse is already doing that by itself, as such asyncGetInput and asyncGetResponse are unnecessary and will only create more lightweight thread that will end up being scheduled/deschedule from the thread pool.
Here's a little cleanup:
open System
open System.Net.Sockets
let rec asyncSendInput (stream : NetworkStream) =
async {
let input = Console.Read() |> BitConverter.GetBytes
input |> Array.iter stream.WriteByte
return! asyncSendInput stream
}
let rec asyncPrintResponse (stream : NetworkStream) =
async {
let response = stream.ReadByte() |> Char.ConvertFromUtf32
Console.Write(response)
return! asyncPrintResponse stream
}
[<EntryPoint>]
let main args =
let client = new System.Net.Sockets.TcpClient()
client.Connect(args.[0], Int32.Parse(args.[1]))
printfn "Connected to %A %A..." args.[0] args.[1]
let stream = client.GetStream()
printfn "Got stream, starting two way asynchronous communication."
asyncSendInput stream |> Async.Start
asyncPrintResponse stream |> Async.RunSynchronously
0
It seems you are using asyncGetInput and asyncGetReponse to introduce concurrency, although this is a noble goal it is kind of useless because you are only using those from other workflows which are already running in the thread pool anyway. In that case it would be ok to make a synchronous call from inside those workflows.
The second point is about the do! at the end of asyncPrintResponse, you should use return! in your recursive call otherwise you will get a memory leak. I'm not sure if we can call this a bug because it can probably be considered normal that the definition of Do in the workflow isn't built for that. I've personally been corrected for that same error here: http://stackoverflow.com/questions/6905251/f-async-difference-between-two-structure