{"comment":{"created_at":"2011-10-25T04:14:55Z","body":"```\r\nIn theory, calling succeed on a deferrable should clear all other callbacks, so the errbacks should not fire. \r\n```\r\nI think this is incorrect. \r\n\r\nLet's look at the code:\r\nhttps://github.com/eventmachine/eventmachine/blob/master/lib/em/deferrable.rb#L141\r\n\r\n* calling succeed does not clear all other callbacks\r\n* As i mentioned, errbacks won't be cleared till all callbacks called. If exception thrown in one of those callbacks, errbacks is still there.","updated_at":"2011-10-25T04:14:55Z","url":"https://api.github.com/repos/igrigorik/em-synchrony/issues/comments/2512798","id":2512798,"user":{"avatar_url":"https://secure.gravatar.com/avatar/73e78865e71cc08cec3a7d51f133c331?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","gravatar_id":"73e78865e71cc08cec3a7d51f133c331","url":"https://api.github.com/users/qqshfox","id":459733,"login":"qqshfox"}},"action":"created","issue":{"number":71,"created_at":"2011-10-24T11:03:35Z","pull_request":{"diff_url":"https://github.com/igrigorik/em-synchrony/pull/71.diff","patch_url":"https://github.com/igrigorik/em-synchrony/pull/71.patch","html_url":"https://github.com/igrigorik/em-synchrony/pull/71"},"body":"related to igrigorik/em-synchrony#69\r\n\r\norigin codes in mysql2 is:\r\n\r\n```ruby\r\ndef notify_readable\r\n  detach\r\n  begin\r\n\t@deferable.succeed(@client.async_result)\r\n  rescue Exception => e\r\n\t@deferable.fail(e)\r\n  end\r\nend\r\n```\r\nException throwed in callback will be catched, and then the errback will be called.\r\n\r\nThe async query method will new a defer, and add a callback and a errback into the chain:\r\n\r\n```ruby\r\ndef query(sql, opts={})\r\n  deferable = aquery(sql, opts)\r\n\r\n  f = Fiber.current\r\n  deferable.callback { |res| f.resume(res) } # *1\r\n  deferable.errback  { |err| f.resume(err) } # *2\r\n\r\n  Fiber.yield.tap do |result|\r\n    raise result if result.is_a?(::Exception)\r\n  end\r\nend\r\n```\r\n*1 if exception thrown here\r\n*2 the errback will be called, and fiber dead :(\r\nSo the fix is: only catch the exception from async_result.","comments":2,"title":"fix mysql2 defer logic","updated_at":"2011-10-25T04:14:55Z","url":"https://api.github.com/repos/igrigorik/em-synchrony/issues/71","id":2032479,"assignee":null,"milestone":null,"closed_at":null,"user":{"avatar_url":"https://secure.gravatar.com/avatar/73e78865e71cc08cec3a7d51f133c331?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","gravatar_id":"73e78865e71cc08cec3a7d51f133c331","url":"https://api.github.com/users/qqshfox","id":459733,"login":"qqshfox"},"html_url":"https://github.com/igrigorik/em-synchrony/issues/71","labels":[],"state":"open"},"legacy":{"issue_id":2032479,"comment_id":2512798}}