]> gitweb.factorcode.org Git - factor.git/blob - extra/zeromq/examples/taskwork.factor
Switch to https urls
[factor.git] / extra / zeromq / examples / taskwork.factor
1 ! Copyright (C) 2012 Eungju PARK.
2 ! See https://factorcode.org/license.txt for BSD license.
3 USING: byte-arrays calendar destructors formatting io kernel
4 math.parser strings threads zeromq zeromq.ffi ;
5 IN: zeromq.examples.taskwork
6
7 : taskwork ( -- )
8     [
9         <zmq-context> &dispose
10
11         [
12             ! Socket to receive messages on
13             ZMQ_PULL <zmq-socket> &dispose
14             dup "tcp://localhost:5557" zmq-connect
15         ] [
16             ! Socket to send messages to
17             ZMQ_PUSH <zmq-socket> &dispose
18             dup "tcp://localhost:5558" zmq-connect
19         ] bi
20
21         ! Process tasks forever
22         [
23             over 0 zmq-recv >string
24             ! Simple progress indicator for the viewer
25             dup "%s." printf flush
26             ! Do the work
27             string>number milliseconds sleep
28             ! Send results to sink
29             dup "" >byte-array 0 zmq-send
30             t
31         ] loop
32
33         drop
34         drop
35     ] with-destructors ;
36
37 MAIN: taskwork