-
Notifications
You must be signed in to change notification settings - Fork 1
/
taskwork.go
44 lines (35 loc) · 875 Bytes
/
taskwork.go
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
//
// 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
//
package main
import (
zmq "github.com/pebbe/zmq3"
"fmt"
"strconv"
"time"
)
func main() {
// Socket to receive messages on
receiver, _ := zmq.NewSocket(zmq.PULL)
defer receiver.Close()
receiver.Connect("tcp://localhost:5557")
// Socket to send messages to
sender, _ := zmq.NewSocket(zmq.PUSH)
defer sender.Close()
sender.Connect("tcp://localhost:5558")
// Process tasks forever
for {
s, _ := receiver.Recv(0)
// Simple progress indicator for the viewer
fmt.Print(s + ".")
// Do the work
msec, _ := strconv.Atoi(s)
time.Sleep(time.Duration(msec) * time.Millisecond)
// Send results to sink
sender.Send("", 0)
}
}