async는 delay 개념이다.
use!, let!, do!는 force 개념이다.
예제:
open System.Net
open System.IO
let wgetAsync url =
async { let request = WebRequest.Create (url:string)
use! response = request.AsyncGetResponse()
use responseStream = response.GetResponseStream()
use reader = new StreamReader(responseStream)
return reader.ReadToEnd() }
let urls = ["http://www.rosettacode.org/"; "http://www.yahoo.com/"; "http://www.google.com/"]
let content = urls
|> List.map wgetAsync
|> Async.Parallel
|> Async.RunSynchronously
(출처: HTTP - Rosetta Code)
에서
use! response = request.AsyncGetResponse()
는
use response = request.GetResponse()
와 동일하다.
'Programming' 카테고리의 다른 글
Racket's inherent problem: read-line (0) | 2021.05.16 |
---|---|
(F#) 스크립트 실행하기 (0) | 2021.05.12 |
(Free Pascal) catch runtime error (0) | 2021.04.10 |
SBCL 에 대한 실망 (0) | 2021.04.05 |
How to convert string to int in C#? (0) | 2021.04.05 |