小编pha*_*121的帖子

什么是F#的异步工作流的Scala等价物?

什么是F#的异步工作流的Scala等价物?

例如,如何跟随F#snippet转换为惯用的Scala?

open System.Net
open Microsoft.FSharp.Control.WebExtensions

let urlList = [ "Microsoft.com", "http://www.microsoft.com/"
                "MSDN", "http://msdn.microsoft.com/"
                "Bing", "http://www.bing.com"
              ]

let fetchAsync(name, url:string) =
    async { 
        try
            let uri = new System.Uri(url)
            let webClient = new WebClient()
            let! html = webClient.AsyncDownloadString(uri)
            printfn "Read %d characters for %s" html.Length name
        with
            | ex -> printfn "%s" (ex.Message);
    }

let runAll() =
    urlList
    |> Seq.map fetchAsync
    |> Async.Parallel 
    |> Async.RunSynchronously
    |> ignore

runAll()
Run Code Online (Sandbox Code Playgroud)

f# scala async-workflow

15
推荐指数
1
解决办法
1935
查看次数

标签 统计

async-workflow ×1

f# ×1

scala ×1