{"action":"created","issue":{"url":"https://api.github.com/repos/reactphp/promise/issues/69","repository_url":"https://api.github.com/repos/reactphp/promise","labels_url":"https://api.github.com/repos/reactphp/promise/issues/69/labels{/name}","comments_url":"https://api.github.com/repos/reactphp/promise/issues/69/comments","events_url":"https://api.github.com/repos/reactphp/promise/issues/69/events","html_url":"https://github.com/reactphp/promise/issues/69","id":185964499,"number":69,"title":"Callback wrapper ?","user":{"login":"Tatikoma","id":1888609,"avatar_url":"https://avatars.githubusercontent.com/u/1888609?v=3","gravatar_id":"","url":"https://api.github.com/users/Tatikoma","html_url":"https://github.com/Tatikoma","followers_url":"https://api.github.com/users/Tatikoma/followers","following_url":"https://api.github.com/users/Tatikoma/following{/other_user}","gists_url":"https://api.github.com/users/Tatikoma/gists{/gist_id}","starred_url":"https://api.github.com/users/Tatikoma/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Tatikoma/subscriptions","organizations_url":"https://api.github.com/users/Tatikoma/orgs","repos_url":"https://api.github.com/users/Tatikoma/repos","events_url":"https://api.github.com/users/Tatikoma/events{/privacy}","received_events_url":"https://api.github.com/users/Tatikoma/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-10-28T16:22:29Z","updated_at":"2016-11-01T10:06:11Z","closed_at":null,"body":"Hello, i writing code using reactphp promise library. I need to call some method and if promise failure then call this method again and again.\n\nFirst time i written next code:\n\n``` php\n$instance = new SomeObject();\n$onSuccess = function(){\n    // do some useful things\n};\n$onFailure = function() use($instance, $onSuccess, &$onFailure){\n    // retry function call\n    $instance->method()->then($onSuccess, $onFailure);\n};\n$instance->method()->then($onSuccess, $onFailure);\n```\n\nThis code have 2 problems:\n1. \"$instance->method()->then()\"  is copypaste. When method has params i need to copypaste more and pass through \"use\" too much params.. \n2. If use this way, then i can write buggy code if accidentally reuse $onFailure because it passed via reference.\n\nTo avoid this issues i had re-written my code:\n\n``` php\nclass CallbackWrapper{\n    public $invoke;\n    public $onSuccess;\n    public $onFailure;\n\n    public function invoke(){\n        call_user_func($this->invoke);\n    }\n}\n\n$instance = new SomeObject();\n\n$callback = new CallbackWrapper();\n$callback->onSuccess = function(){\n    // do some useful things\n};\n$callback->onFailure = function() use($callback){\n    $callback->invoke();\n};\n$callback->invoke = function() use($instance, $callback){\n    $instance->method()->then($callback->onSuccess, $callback->onFailure);\n};\n$callback->invoke();\n```\n\nI see no issues with this code, but have a practical trouble - i need this helper in the majority of projects that uses promises. So maybe it makes sense to include such a helper to the promise library? Or may be i miss something and promise library has another ways to do it?\n\nSorry for my clumsy English.\n"},"comment":{"url":"https://api.github.com/repos/reactphp/promise/issues/comments/257529794","html_url":"https://github.com/reactphp/promise/issues/69#issuecomment-257529794","issue_url":"https://api.github.com/repos/reactphp/promise/issues/69","id":257529794,"user":{"login":"Tatikoma","id":1888609,"avatar_url":"https://avatars.githubusercontent.com/u/1888609?v=3","gravatar_id":"","url":"https://api.github.com/users/Tatikoma","html_url":"https://github.com/Tatikoma","followers_url":"https://api.github.com/users/Tatikoma/followers","following_url":"https://api.github.com/users/Tatikoma/following{/other_user}","gists_url":"https://api.github.com/users/Tatikoma/gists{/gist_id}","starred_url":"https://api.github.com/users/Tatikoma/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Tatikoma/subscriptions","organizations_url":"https://api.github.com/users/Tatikoma/orgs","repos_url":"https://api.github.com/users/Tatikoma/repos","events_url":"https://api.github.com/users/Tatikoma/events{/privacy}","received_events_url":"https://api.github.com/users/Tatikoma/received_events","type":"User","site_admin":false},"created_at":"2016-11-01T10:06:11Z","updated_at":"2016-11-01T10:06:11Z","body":"Yes, it can solve my task. I'm talking about that helper code like this might need to be included to promise library."}}
{"actor":{"display_login":"Tatikoma"}}