<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: ao_sleep code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Tue, 07 Oct 2008 07:36:05 GMT</pubDate>
    <description>DZone Snippets: ao_sleep code</description>
    <item>
      <title>Using ao_sleep</title>
      <link>http://snippets.dzone.com/posts/show/738</link>
      <description>In python for series 60, the use of e32.ao_sleep is encourage&lt;br /&gt;over time.sleep. AO stands for 'Active Object' approach to&lt;br /&gt;cooperative multi-tasking. When an object go to 'ao_sleep'&lt;br /&gt;other active objects can run.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;import e32&lt;br /&gt;e32.ao_sleep(5)  # sleep for 5 seconds&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;There is another usage ao_sleep(interval, callback)&lt;br /&gt;where ao_sleep will return immediately but the callback&lt;br /&gt;will be called after the interval (in another thread?)&lt;br /&gt;&lt;br /&gt;This could be used to create a repeat loop for every interval.&lt;br /&gt;I show this in &lt;a href=http://bigbold.com/snippets/posts/show/730&gt;a previous snippet&lt;/a&gt;.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;import e32, time&lt;br /&gt;&lt;br /&gt;def showtime():&lt;br /&gt;  print time.clock()&lt;br /&gt;  e32.ao_sleep(1, showtime)  # sleep then call itself again&lt;br /&gt;&lt;br /&gt;showtime()  # start the loop&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sun, 18 Sep 2005 13:59:03 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/738</guid>
      <author>korakot (Korakot Chaovavanich)</author>
    </item>
  </channel>
</rss>
