/tutorial/signal/example0.e

http://github.com/tybor/Liberty · Specman e · 38 lines · 25 code · 6 blank · 7 comment · 3 complexity · d9866e3d8578b5f553ed1fdf5c180d98 MD5 · raw file

  1. class EXAMPLE0
  2. -- Signal example0
  3. -- This example shows the use of SIGNAL_0. This signal only means that an
  4. -- event occurred.
  5. create {ANY}
  6. make
  7. feature {}
  8. event: SIGNAL_0
  9. make
  10. do
  11. create event.make
  12. register
  13. io.put_string("Event occur for first time:%N")
  14. event.emit
  15. io.put_string("Event occur for second time:%N")
  16. event.emit
  17. end
  18. register
  19. -- In real examples, other objects will connect to the event so
  20. -- arbitrary functions of their choice may be executed when the
  21. -- event occur.
  22. do
  23. event.connect(agent io.put_string("Event occur...%N"))
  24. -- functions with arguments may be used too! Simply give their values.
  25. event.connect(agent foo)
  26. end
  27. foo
  28. do
  29. io.put_string(once "This function does what needs to be%
  30. % done for this event%N")
  31. end
  32. end -- class EXAMPLE0