I ended up using MailboxProcessor. Somewhat like the example in Expert F#.

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
53
54
55
56
57
58
59
60
61
62
open Microsoft.FSharp.Control

type Message<'a> =

 | Die // quit

    | Fetch of MailboxProcessor<'a> // get the current state

    | Deliver of 'a // replace the current state

    //| Some of int

    

let interactiveFunction f f_zero =

    MailboxProcessor.Start(fun inbox ->

        let rec loop x =

            async {

                //let! msg = inbox.Receive()

                let! tryMsg = inbox.TryReceive(timeout=0)

                match tryMsg with

                    | None ->

                        //printfn "loop %d" x

                        return! loop (f x)

                    | Some msg ->

                        match msg with

                            | Die -> ()

                            | Fetch replyChannel ->

                                //printfn "Fetch %d" x

                                // post response to reply channel and continue

                                do replyChannel.Post(x)

                                return! loop (f x) 

                            | Deliver m ->

                                //printfn "Deliver %d" m

                                //printfn "Replace %d" x

                                return! loop m

                }

        loop f_zero)
By on 4/9/2009 7:35 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper