I wonder if this is too a broad question, but recently I made myself to come across a piece of code I\'d like to be certain on how to translate from C# into proper F#. The j
You can use use TaskBuilder
in FSharpx and pass in TaskScheduler.Current
. Here's my attempt at translating RefreshHubs
. Note that Task<unit>
is used in lieu of Task
.
let RefreshHubs _ =
let task = TaskBuilder(scheduler = TaskScheduler.Current)
task {
let addresses =
RoleEnvironment.Roles.["GPSTracker.Web"].Instances
|> Seq.map (fun instance ->
let endpoint = instance.InstanceEndpoints.["InternalSignalR"]
sprintf "http://%O" endpoint.IPEndpoint
)
|> Seq.toList
let newHubs = addresses |> List.filter (not << hubs.ContainsKey)
let deadHubs = hubs.Keys |> Seq.filter (fun x ->
not (List.exists ((=) x) addresses))
// remove dead hubs
deadHubs |> Seq.iter (hubs.Remove >> ignore)
// add new hubs
let! _ = Task.WhenAll [| for hub in newHubs -> AddHub hub |]
return ()
}