forked from booksbyus/zguide
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mtrelay.fsx
52 lines (41 loc) · 1.15 KB
/
mtrelay.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
43
44
45
46
47
48
49
50
51
52
(*
Multithreaded relay
*)
#r @"bin/fszmq.dll"
open fszmq
open fszmq.Context
open fszmq.Socket
#load "zhelpers.fs"
open System.Threading
let step1 (o:obj) =
// connect to step2 and tell it we're ready
use xmitter = (o :?> Context) |> pair
"inproc://step2" |> connect xmitter
printfn "Step 1 ready, signaling step 2"
"READY" |> s_send xmitter
let step2 (o:obj) =
let context : Context = downcast o
// bind inproc socket before starting step1
use receiver = pair context
"inproc://step2" |> bind receiver
let t = Thread(ParameterizedThreadStart step1)
t.Start(o)
// wait for signal and pass it on
s_recv receiver |> ignore
// connect to step3 and tell it we're ready
use xmitter = pair context
"inproc://step3" |> connect xmitter
printfn "Step 2 ready, signaling step 3"
"READY" |> s_send xmitter
let main () =
use context = new Context(1)
// bind inproc socket before starting step2
use receiver = pair context
"inproc://step3" |> bind receiver
let t = Thread(ParameterizedThreadStart step2)
t.Start(context)
// wait for signal
s_recv receiver |> ignore
printfn "Test successful"
EXIT_SUCCESS
main ()