Skip to content

Commit 7522f86

Browse files
committed
WIP parallel processor
1 parent d0f4180 commit 7522f86

2 files changed

Lines changed: 37 additions & 5 deletions

File tree

tests/FSharp.Compiler.Service.Tests2/Program.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ let runCompiler () =
88

99
[<EntryPoint>]
1010
let main _ =
11-
TestDepResolving.TestProject(@"C:\projekty\fsharp\heuristic\tests\FSharp.Compiler.ComponentTests\FSharp.Compiler.ComponentTests.fsproj")
12-
// runCompiler ()
11+
//TestDepResolving.TestProject(@"C:\projekty\fsharp\heuristic\tests\FSharp.Compiler.ComponentTests\FSharp.Compiler.ComponentTests.fsproj")
12+
runCompiler ()
1313
0
Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,41 @@
11
module FSharp.Compiler.Service.Tests.RunCompiler
22

3+
open System.Collections.Concurrent
4+
open System.Threading
5+
open System.Threading.Tasks
36
open NUnit.Framework
47

58
[<Test>]
69
let runCompiler () =
7-
let args =
8-
System.IO.File.ReadAllLines(@"C:\projekty\fsharp\heuristic\tests\FSharp.Compiler.Service.Tests2\args.txt") |> Array.skip 1
9-
FSharp.Compiler.CommandLineMain.main args |> ignore
10+
// let args =
11+
// System.IO.File.ReadAllLines(@"C:\projekty\fsharp\heuristic\tests\FSharp.Compiler.Service.Tests2\args.txt") |> Array.skip 1
12+
// FSharp.Compiler.CommandLineMain.main args |> ignore
13+
14+
let go (idx : int) =
15+
printfn $"{idx} start"
16+
Thread.Sleep(1000)
17+
printfn $"{idx} stop"
18+
19+
printfn "start"
20+
use q = new BlockingCollection<int>()
21+
let work (idx : int) =
22+
printfn $"start worker {idx}"
23+
q.GetConsumingEnumerable()
24+
|> Seq.iter go
25+
printfn $"end worker {idx}"
26+
let maxParallel = 4
27+
printfn "workers"
28+
let workers =
29+
[|1..maxParallel|]
30+
|> Array.map (fun idx -> Task.Factory.StartNew(fun () -> work idx))
31+
32+
printfn "adding"
33+
for i in [|1..20|] do
34+
q.Add(i)
35+
Thread.Sleep(300)
36+
printfn "CompleteAdding"
37+
q.CompleteAdding()
38+
printfn "waitall"
39+
Task.WaitAll workers
40+
printfn "End"
41+
()

0 commit comments

Comments
 (0)