/
AsyncFileExtensions.fsx
42 lines (26 loc) · 1.33 KB
/
AsyncFileExtensions.fsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#r @"../../bin/v4.0/FSharpx.Extras.dll"
open FSharpx.Control
let lines = [| for n in 1..100000 do
let str = sprintf "line: %d" n
yield str |]
let asyncWriteA = System.IO.File.AsyncWriteAllLines(@"c:\tmp\a.txt", lines)
let asyncWriteB = System.IO.File.AsyncWriteAllLines(@"c:\tmp\b.txt", lines)
let asyncWriteC = System.IO.File.AsyncWriteAllLines(@"c:\tmp\c.txt", lines)
let asyncWriteD = System.IO.File.AsyncWriteAllLines(@"c:\tmp\d.txt", lines)
let asyncWriteE = System.IO.File.AsyncWriteAllText( @"c:\tmp\e.txt", "this is some text\n")
printfn "async write all lines beginning"
[|asyncWriteA; asyncWriteB; asyncWriteC; asyncWriteD; asyncWriteE|]
|> Async.Parallel
|> Async.RunSynchronously
|> ignore
let asyncAppendA = System.IO.File.AsyncAppendAllLines(@"c:\tmp\a.txt", lines)
let asyncAppendB = System.IO.File.AsyncAppendAllLines(@"c:\tmp\b.txt", lines)
let asyncAppendC = System.IO.File.AsyncAppendAllLines(@"c:\tmp\c.txt", lines)
let asyncAppendD = System.IO.File.AsyncAppendAllLines(@"c:\tmp\d.txt", lines)
let asyncAppendE = System.IO.File.AsyncAppendAllText( @"c:\tmp\e.txt", "this is some more text\n")
[|asyncAppendA;asyncAppendB;asyncAppendC;asyncAppendD; asyncAppendE|]
|> Async.Parallel
|> Async.RunSynchronously
|> ignore
printfn "async append all lines complete"