let reply = ref ""
let doAuto =
async {
let! resultAA =
async { return SqlCmd.aaHits query |> Async.RunSynchronously |> List.ofSeq }
let! resultBB =
async { return SqlCmd.bbHits query |> Async.RunSynchronously |> List.ofSeq }
let! resultCC =
async { return SqlCmd.ccHits query |> Async.RunSynchronously |> List.ofSeq }
let! resultDD =
async { return SqlCmd.ddHits query |> Async.RunSynchronously |> List.ofSeq }
let! resultEE =
async { return SqlCmd.ddHits query |> Async.RunSynchronously |> List.ofSeq }
let! resultFF =
async { return SqlCmd.ffHits query |> Async.RunSynchronously |> List.ofSeq }
let! resultGG =
async { return SqlCmd.ggHits query |> Async.RunSynchronously |> List.ofSeq }
let! resultHH =
async { return SqlCmd.hhHits query |> Async.RunSynchronously |> List.ofSeq }
let! resultII =
async { return SqlCmd.iiHits query |> Async.RunSynchronously |> List.ofSeq }
let! resultJJ =
async { return SqlCmd.jjHits query |> Async.RunSynchronously |> List.ofSeq }
let! resultKK =
async { return SqlCmd.kkHits query |> Async.RunSynchronously |> List.ofSeq }
let length1 = resultAA.Length + resultBB.Length
if length1 > 9 then reply := "hey " + length1.ToString()
else
let x = resultCC.Length + resultDD.Length + resultEE.Length + resultFF.Length + resultGG.Length
+ resultHH.Length + resultII.Length + resultJJ.Length + resultKK.Length + length1
reply := x.ToString()
} |> Async.StartImmediate
!reply
The typical SqlCmd.xxHits
(in module SqlCmd
) built using FSharp.Data.SqlCommandTypeProvider
looks like this:
[<Literal>]
let sqlXX = "SELECT ...@startsWith..."
type QueryXX = SqlCommand<sqlXX, ConnectionStringName=...>
let xxHits query =
let cmdXxHits = QueryXX(connectionString = connectionString, startsWith = query)
cmdXxHits.AsyncExecute()
I'm pretty inexperienced at using async. Looking for feedback, especially in a couple of areas:
I couldn't think of a better way to get my results out from inside the outer async than the ref. From what I read it sounded like
Async.StartImmediate
was the best solution for something running in an IIS application.From the results of the first 2 inner asyncs, I may choose to quit before waiting for any more completions. Should I really be cancelling the remaining asyncs? Does it matter?