{"action":"created","issue":{"url":"https://api.github.com/repos/celluloid/celluloid/issues/386","labels_url":"https://api.github.com/repos/celluloid/celluloid/issues/386/labels{/name}","comments_url":"https://api.github.com/repos/celluloid/celluloid/issues/386/comments","events_url":"https://api.github.com/repos/celluloid/celluloid/issues/386/events","html_url":"https://github.com/celluloid/celluloid/issues/386","id":27431796,"number":386,"title":"Wrapping multiple objects with the same Cell","user":{"login":"jnicklas","id":134,"avatar_url":"https://avatars.githubusercontent.com/u/134?v=3","gravatar_id":"","url":"https://api.github.com/users/jnicklas","html_url":"https://github.com/jnicklas","followers_url":"https://api.github.com/users/jnicklas/followers","following_url":"https://api.github.com/users/jnicklas/following{/other_user}","gists_url":"https://api.github.com/users/jnicklas/gists{/gist_id}","starred_url":"https://api.github.com/users/jnicklas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jnicklas/subscriptions","organizations_url":"https://api.github.com/users/jnicklas/orgs","repos_url":"https://api.github.com/users/jnicklas/repos","events_url":"https://api.github.com/users/jnicklas/events{/privacy}","received_events_url":"https://api.github.com/users/jnicklas/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/celluloid/celluloid/labels/reassess","name":"reassess","color":"f7c6c7"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2014-02-12T13:07:18Z","updated_at":"2015-03-28T13:57:16Z","closed_at":null,"body":"I'm not 100% sure I understand the Cell/Actor refactoring, but it's my understanding, that a Cell wraps an arbitrary object in an actor. I just ran into a situation where I'd like multiple objects to share the same Mailbox, basically because I don't want to put all methods on the same objects, since that wouldn't follow the single responsibility principle, but I also want it to be possible to pass the object off to another actor (or even a non-actor) and still preserve thread safety.\r\n\r\nI did a pretty ugly workaround:\r\n\r\n``` ruby\r\nclass Base\r\n  include Celluloid\r\n\r\n  def initialize(socket)\r\n    @session = Session.new(self)\r\n  end\r\n\r\n  def schedule\r\n    yield\r\n  end\r\n  execute_block_on_receiver :schedule\r\nend\r\n```\r\n``` ruby\r\nclass Session\r\n  def initialize(app)\r\n    @app = app\r\n    @app_actor = Celluloid::Actor.current\r\n    @subscriptions = []\r\n  end\r\n\r\n  def subscribe(subscriber)\r\n    @app_actor.schedule { @subscriptions << subscriber }\r\n  end\r\nend\r\n```\r\n\r\nNow `@session` can be passed to another actor, but it remains thread-safe, since it uses `Base`'s mailbox to prevent concurrent modification.\r\n\r\nMy thinking was that something like the following would be nice:\r\n\r\n``` ruby\r\nclass Base\r\n  include Celluloid\r\n\r\n  def initialize(socket)\r\n    @session = Cell.new(Session.new(self), Actor.current)\r\n  end\r\nend\r\n```\r\n``` ruby\r\nclass Session\r\n  def initialize(app)\r\n    @app = app\r\n    @subscriptions = []\r\n  end\r\n\r\n  def subscribe(subscriber)\r\n    @subscriptions << subscriber\r\n  end\r\nend\r\n```\r\n\r\nNow if we ever pass off `@session` to someone else, they'll be using `Session` encapsulated in a cell which uses the same mailbox as the current actor.\r\n\r\nReading the code, this actually shouldn't be too difficult to implement. I could take a stab at it if you guys think this is a sensible idea.\r\n\r\nOf course, I haven't really thought this through, so it might be a totally terrible idea.\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/celluloid/celluloid/issues/comments/87232369","html_url":"https://github.com/celluloid/celluloid/issues/386#issuecomment-87232369","issue_url":"https://api.github.com/repos/celluloid/celluloid/issues/386","id":87232369,"user":{"login":"digitalextremist","id":21095,"avatar_url":"https://avatars.githubusercontent.com/u/21095?v=3","gravatar_id":"","url":"https://api.github.com/users/digitalextremist","html_url":"https://github.com/digitalextremist","followers_url":"https://api.github.com/users/digitalextremist/followers","following_url":"https://api.github.com/users/digitalextremist/following{/other_user}","gists_url":"https://api.github.com/users/digitalextremist/gists{/gist_id}","starred_url":"https://api.github.com/users/digitalextremist/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/digitalextremist/subscriptions","organizations_url":"https://api.github.com/users/digitalextremist/orgs","repos_url":"https://api.github.com/users/digitalextremist/repos","events_url":"https://api.github.com/users/digitalextremist/events{/privacy}","received_events_url":"https://api.github.com/users/digitalextremist/received_events","type":"User","site_admin":false},"created_at":"2015-03-28T13:57:16Z","updated_at":"2015-03-28T13:57:16Z","body":"@jnicklas thanks for the response on this -- I'll check back on it after an overall audit."}}