]> gitweb.factorcode.org Git - factor.git/blob - extra/zeromq/examples/tasksink.factor
core: Rename iota to <iota> so we can have TUPLE: iota ... ; instead of TUPLE: iota...
[factor.git] / extra / zeromq / examples / tasksink.factor
1 ! Copyright (C) 2012 Eungju PARK.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: byte-arrays calendar destructors formatting io kernel
4 math strings sequences zeromq zeromq.ffi ;
5 IN: zeromq.examples.tasksink
6
7 : tasksink ( -- )
8     [
9         <zmq-context> &dispose
10         ZMQ_PULL <zmq-socket> &dispose
11         dup "tcp://*:5558" zmq-bind
12         ! Wait for start of batch
13         dup 0 zmq-recv drop
14         ! Start our clock now
15         now
16         ! Process 100 confirmations
17         100 <iota> [
18             pick 0 zmq-recv drop
19             10 rem zero? [ ":" ] [ "." ] if write flush
20         ] each
21         ! Calculate and report duration of batch
22         now swap time- duration>milliseconds "Total elapsed time: %d msec\n" printf
23         drop
24     ] with-destructors ;
25
26 MAIN: tasksink