PageRenderTime 14ms CodeModel.GetById 12ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/tutorial/sequencer/example3.e

http://github.com/tybor/Liberty
Specman e | 77 lines | 62 code | 12 blank | 3 comment | 0 complexity | 6aa24ed094d1f73ec45838b6defd8cb6 MD5 | raw file
 1class EXAMPLE3
 2   -- This example shows how to use periodic jobs.
 3   -- The user will see a rolling stick, it's position will change 10
 4   -- times per second. Every 3 seconds the program prints the progress report.
 5
 6create {ANY}
 7   make
 8
 9feature {}
10   lm: LOOP_STACK
11
12   counter2: INTEGER
13
14   counter: INTEGER
15
16   old_counter: INTEGER
17
18   time: MICROSECOND_TIME
19
20   make
21      do
22         time.update
23         create lm.make
24         lm.add_job(create {SIMPLE_BACKGROUND_JOB}.set_work(agent do_count, Void, 1))
25         lm.add_job(create {SIMPLE_PERIODIC_JOB}.set_work(agent running, Void, 1, 0.5))
26         lm.add_job(create {SIMPLE_PERIODIC_JOB}.set_work(agent progress_print, Void, 0, 3))
27         lm.run
28      end
29
30   done: BOOLEAN
31
32   do_count: BOOLEAN
33      do
34         counter := counter + 1
35         Result := not done
36      end
37
38   running: BOOLEAN
39      local
40         s: STRING
41      do
42         inspect
43            counter2 \\ 4
44         when 0 then
45            s := "%R-"
46         when 1 then
47            s := "%R/"
48         when 2 then
49            s := "%R|"
50         when 3 then
51            s := "%R\"
52         end
53         io.put_string(s)
54         io.flush
55         counter2 := counter2 + 1
56         Result := not done
57      end
58
59   progress_print: BOOLEAN
60      local
61         now: MICROSECOND_TIME
62      do
63         io.put_string("%Rcounter = ")
64         io.put_integer(counter)
65         io.put_string(", work done = ")
66         io.put_integer(counter - old_counter)
67         io.put_string(", elapsed time : ")
68         now.update
69         io.put_real(time.elapsed_seconds(now))
70         time := now
71         io.put_new_line
72         old_counter := counter
73         done := counter > 10000
74         Result := not done
75      end
76
77end -- class EXAMPLE3