{"issue":{"pull_request":{"diff_url":null,"html_url":null,"patch_url":null},"state":"open","user":{"avatar_url":"https://secure.gravatar.com/avatar/7aa02977cf2fe210e354e2a358a88d77?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","gravatar_id":"7aa02977cf2fe210e354e2a358a88d77","url":"https://api.github.com/users/slyphon","login":"slyphon","id":46660},"milestone":null,"labels":[],"assignee":null,"updated_at":"2011-10-29T03:16:11Z","comments":0,"closed_at":null,"url":"https://api.github.com/repos/igrigorik/em-synchrony/issues/75","body":"Hi!\r\n\r\nI'm working on providing an em-synchrony friendly version of [ZK::EventMachine](https://github.com/slyphon/zk-eventmachine/tree/dev/synchrony), but have run into trouble with the way that EM::Synchrony.sync handles callbacks that have their `succeed` method invoked with multiple arguments. I make extensive use of this pattern throughout my code, so for me this is a pretty important thing to have working :)\r\n\r\nBelow I have an example fix for sync. I created a fork and branch of em-synchrony and made the change, but I couldn't figure out how to set up all of the required dependencies to run the specs. \r\n\r\nI've included below a small demonstration of the problem (for me) and the proposed fix. If it's easier for you, you can also check out [a gist](https://gist.github.com/1324024) of this code and run it that way. \r\n\r\nThe change is pretty minor, if you can instruct me on how to configure mongo and mysql, etc. so I can run the test suite, i'd be happy to. If you don't mind making the change in your environment and seeing if there are any ill effects, that'd work too.\r\n\r\n\r\n\r\n```ruby\r\n#!/usr/bin/env ruby\r\n\r\nrequire 'rubygems'\r\nrequire 'eventmachine'\r\nrequire 'em-synchrony'\r\n\r\nmodule EventMachine\r\n  module Synchrony\r\n    def self.new_sync(df)\r\n      f = Fiber.current\r\n      xback = proc {|*args|\r\n        if f == Fiber.current\r\n          return *args\r\n        else\r\n          f.resume(*args)\r\n        end\r\n      }\r\n      df.callback &xback\r\n      df.errback &xback\r\n\r\n      Fiber.yield\r\n    end\r\n  end\r\nend\r\n\r\ndef gimme_deferreds\r\n  a, b = EM::DefaultDeferrable.new, EM::DefaultDeferrable.new\r\n\r\n  EM.next_tick do\r\n    a.succeed(1, 2, [:foo, :bar])\r\n    b.succeed(:single_arg)\r\n  end\r\n\r\n  return a, b\r\nend\r\n\r\n\r\ndef current_implementation\r\n  EM.synchrony do\r\n    a, b = gimme_deferreds\r\n\r\n    rval = EM::Synchrony.sync(a)\r\n    puts \"a rval: #{rval.inspect}\"\r\n\r\n    rval = EM::Synchrony.sync(b)\r\n    puts \"b rval: #{rval.inspect}\"\r\n\r\n    EM.next_tick { EM.stop_event_loop }\r\n  end\r\nend\r\n\r\ndef proposed_fix\r\n  EM.synchrony do\r\n    a, b = gimme_deferreds\r\n\r\n    rval = EM::Synchrony.new_sync(a)\r\n    puts \"a rval: #{rval.inspect}\"\r\n\r\n    rval = EM::Synchrony.new_sync(b)\r\n    puts \"b rval: #{rval.inspect}\"\r\n\r\n    EM.next_tick { EM.stop_event_loop }\r\n  end\r\nend\r\n\r\n\r\nif __FILE__ == $0\r\n  puts <<-EOS\r\ncall signature: \r\na.succeed(1, 2, [:foo, :bar])\r\nb.succeed(:single_arg)\r\n\r\n  EOS\r\n\r\n  puts \"this is the return value of the current implementation:\"\r\n  current_implementation\r\n\r\n  puts \"\\nthis is the proposed change:\"\r\n  proposed_fix\r\nend\r\n\r\n__END__\r\n\r\ncall signature:\r\na.succeed(1, 2, [:foo, :bar])\r\nb.succeed(:single_arg)\r\n\r\nthis is the return value of the current implementation:\r\na rval: 1\r\nb rval: :single_arg\r\n\r\nthis is the proposed change:\r\na rval: [1, 2, [:foo, :bar]]\r\nb rval: :single_arg\r\n```\r\n\r\nThanks!\r\nJonathan\r\n\r\n","html_url":"https://github.com/igrigorik/em-synchrony/issues/75","number":75,"title":"Potential improvement to EM::Synchrony.sync handling of Deferrables called with multiple arguments","id":2085622,"created_at":"2011-10-29T03:16:11Z"},"action":"opened"}