Search code examples
rubymotion

Problems with asynchronous calls using motion-resource and BubbleWrap for Ruby Motion


I'm trying to follow the example from motion-resource https://github.com/tkadauke/motion-resource. Having difficulty getting the data in the correct format with this asynchronous code:

def all_friends(&block)
  Friends.find_all do |friends, response|
    if response.ok?
      puts friends.inspect
      block.call friends
    else
      App.alert response.error_message
    end
  end
end

In this implementation I have a user resource that has many friends. I'm trying to find all the friends for this user with User.current.all_friends

I'm getting an error when the data comes back when I try to iterate through it because its coming back as a BubbleWrap HTTP Query.

#<BubbleWrap::HTTP::Query:0xc54c7a0 ...> 

Solution

  • This Stack Stack overflow question addresses the same problems experienced in this question: What is the iOS (or RubyMotion) idiom for waiting on a block that executes asynchronously?