title: In RubyMotion how do you cancel a list refresh when the back link is touched?
body: <p>I'm new to RubyMotion and struggling to get to grips with some of the APIs.</p>
  
  <p>My app is a very basic series of UITable lists, if you select an item you go into the list for that item which is achieved by pushing a new controller.</p>
  
  <p>This all works fine, but in my viewDidLoad method for one of the list controllers I'm calling a method that refreshes the data for the list from the internet.  I'm running the refresh in an asynchronous Dispatch queue, so viewDidLoad looks like this:</p>
  
  <pre><code>def viewDidLoad
    super
  
    loadItems
  
    Dispatch::Queue.concurrent.async do
      refreshItems
    end
  end
  </code></pre>
  
  <p>The problem I have is if I go into this list, wait for the refresh to complete (via tailing debug logs) then go back out and into another list it's fine, but if I go in and go immediately back out and into another list before the refresh has completed, the application crashes with a nondescript error which I'm reliably informed is a segfault.</p>
  
  <p>So I'm fairly sure I need to either wait for the refresh to complete before closing the controller or somehow kill the refresh thread from the Dispatch queue before closing the controller.  So my questions are:</p>
  
  <ol>
  <li><p>How do you catch the "back" event when you press in the top left to go back and close the current controller?  You get this functionality for free when pushing the controller, but I'm not sure how to catch the back event.</p></li>
  <li><p>Which is the correct approach, kill the refresh thread before closing the controller or just wait for it to complete?  Killing it seems a bit unsafe, perhaps I could send it a message asking it to finish what it's doing and exit, and then wait for it to respond saying ok done.</p></li>
  <li><p>How do you achieve whichever is the correct answer to question 2?  If I knew how to send a message back to the main thread from the Dispatch'd thread that would make this a bit simpler.</p></li>
  </ol>