Timer example

Timers are handy to notify program when some time interval expires.

Compilation

Easiest way to get this example running is to go to examples directory in package root, and run:

$ ./build.sh timer

build.sh script compiles Ano script to C, copies source files in place and pops up instructions what to do next. Follow them. Check also examples/README for more info.

Preview

; ------------------------------------------------------------------------------
; timer.ano
;
; To compile:
;
; $ ./build/ano ./examples/timer/timer.ano > \
;     engine/dsl_ano.h
; ------------------------------------------------------------------------------
;
@ANO_SCRIPT_NAME		timer
@ANO_SCRIPT_VERSION		0.0.1
@ANO_SCRIPT_DESCRIPTION	Simple timer
;
@ANO_FLAGS_USE_PROTOS		[ ]
@ANO_FLAGS_VAR_NAME_SUBS	[ ]
@ANO_FLAGS_VAR_WARN_UNUSED	[ ]
;
; Copyright © 2016-2026, Jani Salonen <salojan@goto10.co>
; All rights reserved.
;
; Timers are handy to notify when some time interval expires.
;

main [exit: 0] {
	; Initialize timer to trigger one second from now. Timer function uses
	; respawn and repeat attributes to trigger itself again five times
	; eighth of a second interval.
	;
	timer (\
		secs: 1, \
		nanosecs: 0, \
		timer: "my_timer")

	; Wait until timers are done.
	;
	print "Press <ctrl-c> or wait five seconds.\n"

	sleep(5, 0)
}

alarm my_timer [respawn: 0:125000, repeat: 5] {
	print "Timer here.\n"
}
; ------------------------------------------------------------------------------
; timer.w2c
;
; To compile:
;
; $ ./build/widget ./examples/timer/timer.w2c > \
;     engine/widget_defs.h
; ------------------------------------------------------------------------------
; ------------------------------------------------------------------------------
; timer.m2c
;
; To compile:
;
; $ ./build/menu ./examples/timer/timer.m2c > \
;     engine/menu_defs.h
; ------------------------------------------------------------------------------

Copyright © 2026, Jani Salonen <salojan at goto10 piste co>. Piste is finnish word and means dot. All rights reserved.