/tutorial/sequencer/example4.e
Specman e | 58 lines | 38 code | 10 blank | 10 comment | 2 complexity | c9378b24f8af1c9d3b72a009bdd3edc2 MD5 | raw file
1class EXAMPLE4 2 -- This example shows that you can enter a new loop and when it 3 -- terminates, the halted loop continues. Loops are managed on a stack. 4 -- This is like opening some modal window, others elements from the 5 -- interface don't work until the modal window is closed. 6 -- NOTE: in real life applications, jobs will probably be complex. In 7 -- this case you have to write a class for that job, inheriting from 8 -- BACKGROUND_JOB or PERIODIC_JOB instead of just using SIMPLE_* versions. 9 10create {ANY} 11 make 12 13feature {} 14 ls: LOOP_STACK 15 16 counter: INTEGER 17 18 make 19 do 20 create ls.make 21 ls.add_job(create {SIMPLE_BACKGROUND_JOB}.set_work(agent work1, Void, 1)) 22 ls.run 23 end 24 25 work1: BOOLEAN 26 do 27 io.put_integer(counter) 28 io.put_new_line 29 counter := counter + 1 30 if counter = 5 then 31 io.put_string("Starting %"modal%" code%N") 32 ls.new_loop 33 -- This new loop will stop when all it's jobs are done. 34 -- The loop can be stopped using 'ls.break' for example 35 -- if the 'Cancel' button in the modal window is pressed. 36 37 ls.add_job(create {SIMPLE_BACKGROUND_JOB}.set_work(agent work2, Void, 1)) 38 io.put_string("The new loop is ready.%N") 39 end 40 41 Result := counter < 10 42 end 43 44 close: BOOLEAN 45 46 work2: BOOLEAN 47 do 48 io.put_string("Modal work%N") 49 if close then 50 io.put_string("Stop modal%N") 51 Result := False 52 else 53 close := True 54 Result := True 55 end 56 end 57 58end -- class EXAMPLE4