ExpandCollapse

+ 1 taskwork.flx

  //
  //  Task worker
  //  Connects PULL socket to tcp://localhost:5557
  //  Collects workloads from ventilator via that socket
  //  Connects PUSH socket to tcp://localhost:5558
  //  Sends results to sink via that socket
  
  include "std/io/faio";
  var sys_clock = #Faio::mk_alarm_clock;
  open ZMQ;
  
  var context = zmq_init (1);
  
  //  Socket to receive messages on
  var receiver = context.mk_socket ZMQ_PULL;
  receiver.connect "tcp://localhost:5557";
  
  //  Socket to send messages to
  var sender = context.mk_socket ZMQ_PUSH;
  sender.connect "tcp://localhost:5558";
  
  //  Process tasks forever
  while true do
    var s = receiver.recv_string;
  
    //  Do the work
    Faio::sleep (sys_clock, atof s); // seconds
  
    //  Send results to sink
    sender.send_string "";
  done