ConradIrwin / em-imap

An event machine based IMAP client
MIT License
69 stars 31 forks source link

"cannot yield from root fiber" when used with EM.synchrony #22

Open JohnMerlino1 opened 8 years ago

JohnMerlino1 commented 8 years ago

I am trying to work with an ActiveRecord object on the callback but I get the error "cannot yield from root fiber":

EM.synchrony do
  User.all.each do |user|
    client = EM::IMAP.new('imap.gmail.com',993,true)

    client.connect.bind! do
          delegate.login(user.email, user.password)
    end.bind! do
          delegate.select('INBOX')
    end.bind! do
          delegate.search('1:20')
    end.bind! do |ids|
          delegate.fetch(ids, "(UID ENVELOPE BODY[TEXT])")
    end.callback do |msgs|
          user.update_attributes body: msgs.attr["BODY[TEXT]"] # Error here: cannot yield from root fiber
    end 
  end  
end

Why does this happen and how can I resolve it?

ConradIrwin commented 8 years ago

Hi @JohnMerlino1, I'm not sure exactly. Unfortunately I haven't used this library in over 4 years, so can't immediately think of anything.

Please let me know if anything comes up.

P.S. What are you trying to build? Looks like fun!

JohnMerlino1 commented 8 years ago

@ConradIrwin I am just trying to understand how the fibers are working. I asked the question on stackoverflow: http://stackoverflow.com/questions/39670727/asynchronous-programming-with-fibers Perhaps you can offer some insights. Thanks.