title: Need help setting sleep to delay the next query in a loop with coldfusion
body: <p>Im running with Coldfusion 11.  I have an instant messenger that uses a meta refresh that refreshes the page every 30 seconds to pull new IMs.  The issue with this is the flash of the page reload and i would really like it to refresh every 15 seconds.  I decided to try to change up and go with looping to check for any unseen messages.  If there is one it would then reload the page.  If not i want it to sleep for 15 seconds before continuing the loop.  As you can see i've set it to do so 40 times.  At 15 second intervals it would time out at 10 minutes.  If a user has not posted a new message or changed the page at that point we consider them logged out.  The code below is at the end of the page.  The issue i'm having is that no messages show until the cloop completes.  Is there a way to set the loop to run in the background yet display current messages?</p>
  
  <pre><code>&lt;cfloop from="1" to="40" index="i"&gt;
  &lt;cfset sleep(15000)&gt; 
  &lt;cfquery name="messck" datasource="mysource" maxrows="1"&gt;
  SELECT id
  FROM messages
  WHERE user = '#getuser.code#' AND friend = '#getme.code#' AND seendate IS NULL
  ORDER BY ID DESC
  &lt;/cfquery&gt;
  &lt;cfif messck.recordcount EQ 0&gt;
  &lt;cfelse&gt;
  &lt;cflocation url="messagebox.cfm?code=#url.code#"&gt;
  &lt;/cfif&gt;
  &lt;/cfloop&gt;
  </code></pre>
  
  <p>Thanks,
  Mike</p>