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

StackOverflow https://stackoverflow.com/questions/21640187

  •  08-10-2022
  •  | 
  •  

Domanda

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 ...> 
È stato utile?

Soluzione 2

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?

Altri suggerimenti

I wonder what line number your error is coming from.

" undefined method `each' for # "

Have you tried removing this line?

block.call friends? 

Your example appears to come from the docs with this working line of code...

User.find_all do |users, response|
  if response.ok?
    puts users.inspect
  else
    App.alert response.error_message
  end
end

Hope you figure it out. It would be easier to troubleshoot if the code was executable.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top