Debian Codegraph @

demo/tasksink.r

raw symbols SCIP
1 ### Task sink from two workers as in the ZeroMQ guide.
2 # SHELL> Rscript taskwork.r &
3 # SHELL> Rscript taskvent.r; Rscript tasksink.r
4 ### Remember to kill two worker processors at the end, such as
5 # SHELL> ps -x|grep "file=task.*\.r"|sed "s/\(.*\) pts.*/\1/"|xargs kill -9
6
7 suppressMessages(library(pbdZMQ, quietly = TRUE))
8
9 ### Initial.
10 context <- zmq.ctx.new()
11 receiver <- zmq.socket(context, ZMQ.ST()$PULL)
12 zmq.bind(receiver, "tcp://*:5558")
13
14 ### Wait for start of batch.
15 string <- zmq.recv(receiver)
16
17 ### Process 100 confirmations.
18 start.time <- Sys.time()
19 for(i in 1:50){
20 string <- zmq.recv(receiver)
21 cat(i, ":", string$buf, "\n")
22 }
23 cat("Total elapsed time:", Sys.time() - start.time, "\n")
24
25 ### Finish.
26 zmq.close(receiver)
27 zmq.ctx.destroy(context)