, : Async.Parallel , , .
. , download downloadAndExtractLinks , AsyncDownloadString WebClient:
let asyncDownload url = async {
let webclient = new System.Net.WebClient()
return! webclient.AsyncDownloadString(System.Uri(url : string)) }
let asyncDownloadAndExtractLinks url = async {
let! html = asyncDownload url
let links = extractLinks html
return url, links.Count }
let pmap f l =
seq { for a in l -> async { return! f a } }
|> Async.Parallel
|> Async.RunSynchronously
. , - , , . . - , , . 10 . , :
let rec asyncRetry times op = async {
try
return! op
with e ->
if times <= 1 then return (reraise e)
else return! asyncRetry (times - 1) op }
, 10 :
let testAsynchronous() =
pmap (asyncRetry 10 downloadAndExtractLinks) urls
. , Async.Parallel ( -, ). , .
- F # - , , - , , - . , , async (, , ).
MSDN , two developerFusion, F #.