-
Notifications
You must be signed in to change notification settings - Fork 0
/
QueryRunner.fs
52 lines (43 loc) · 1.55 KB
/
QueryRunner.fs
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
43
44
45
46
47
48
49
50
51
52
module QueryRunner
type AggregateFunction = Intersect | Union
type Query =
| SimpleQuery of string
| ComplexQuery of AggregateFunction * Query list
let aggregateResults aggregate =
match aggregate with
| Intersect -> Set.intersectMany
| Union -> Set.unionMany
let rec runQuery executor query =
match query with
| SimpleQuery q -> executor q
| ComplexQuery (aggregateFunction,queries) ->
queries
|> Seq.map (fun q -> runQuery executor q)
|> Set.ofSeq
|> aggregateResults aggregateFunction
#nowarn "40"
type countMsg =
| Die
| Incr of int
| Fetch of AsyncReplyChannel<int>
let printerAgent = MailboxProcessor.Start(fun inbox->
// the message processing function
let rec messageLoop = async{
// read a message
let! msg = inbox.Receive()
// process a message
match msg with
| Die -> return ()
| Incr x -> return! messageLoop
| Fetch(reply) ->
reply.Reply(1);
return! messageLoop
// loop to top
return! messageLoop
}
// start the loop
messageLoop
)
let compute =
printerAgent.PostAndAsyncReply (fun reply -> Fetch(reply))
|> Async.RunSynchronously