fszmq


Node Coordination

Synchronized subscriber

 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: 
#r "fszmq.dll"
open fszmq
open System.Threading

let main () =
  use context = new Context ()

  // first, connect our subscriber socket
  use subscriber = Context.sub context
  Socket.connect subscriber "tcp://localhost:5561"
  Socket.subscribe subscriber [| ""B |]

  // 0MQ is so fast, we need to wait a while
  Thread.Sleep 1

  // second, synchronize with publisher
  use syncclient = Context.req context
  Socket.connect syncclient "tcp://localhost:5562"

  // - send a synchronization request
  ""B |> Socket.send syncclient

  // - wait for a synchronization reply
  syncclient
  |> Socket.recv
  |> ignore

  // third, get our updates and report how many we got
  let rec loop update_nbr =
    let msg = Socket.recv subscriber
    match msg with
    | "END"B  ->  update_nbr
    | _       ->  loop (update_nbr + 1)
  printfn "Received %d updates" <| loop 0

  0 // return code
module docs
module PATH

from docs
val hijack : unit -> unit

Full name: docs.PATH.hijack
namespace fszmq
namespace System
namespace System.Threading
val main : unit -> int

Full name: Syncsub.main
val context : System.IDisposable
val subscriber : System.IDisposable
Multiple items
type Thread =
  inherit CriticalFinalizerObject
  new : start:ThreadStart -> Thread + 3 overloads
  member Abort : unit -> unit + 1 overload
  member ApartmentState : ApartmentState with get, set
  member CurrentCulture : CultureInfo with get, set
  member CurrentUICulture : CultureInfo with get, set
  member DisableComObjectEagerCleanup : unit -> unit
  member ExecutionContext : ExecutionContext
  member GetApartmentState : unit -> ApartmentState
  member GetCompressedStack : unit -> CompressedStack
  member GetHashCode : unit -> int
  ...

Full name: System.Threading.Thread

--------------------
Thread(start: ThreadStart) : unit
Thread(start: ParameterizedThreadStart) : unit
Thread(start: ThreadStart, maxStackSize: int) : unit
Thread(start: ParameterizedThreadStart, maxStackSize: int) : unit
Thread.Sleep(timeout: System.TimeSpan) : unit
Thread.Sleep(millisecondsTimeout: int) : unit
val syncclient : System.IDisposable
val ignore : value:'T -> unit

Full name: Microsoft.FSharp.Core.Operators.ignore
val loop : (int -> int)
val update_nbr : int
val msg : byte []
val printfn : format:Printf.TextWriterFormat<'T> -> 'T

Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.printfn
val release : unit -> unit

Full name: docs.PATH.release
Fork me on GitHub