Over a million developers have joined DZone.

Using Ao_timer For A Better Sleep

DZone's Guide to

Using Ao_timer For A Better Sleep

· ·
Free Resource
A few of my old examples include 'unsafe' use of e32.ao_sleep().
The problem is that the sleep can't be interrupted.
I often use a convenient loop like this

while running:
  // do something
  e32.ao_sleep(1)  # sleep a sec

Now in pys60 1.3.1, it's better to use e32.Ao_timer

timer = e32.Ao_timer()
while running:
  // do something
  timer.after(1)   # sleep a sec

I can then interupt the sleep with timer.cancel()
in other part of the program if I need to continue the loop.

For example, I can end the application without waiting for
the last second.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}