{"action":"created","issue":{"url":"https://api.github.com/repos/webdriverio/webdriverio/issues/999","labels_url":"https://api.github.com/repos/webdriverio/webdriverio/issues/999/labels{/name}","comments_url":"https://api.github.com/repos/webdriverio/webdriverio/issues/999/comments","events_url":"https://api.github.com/repos/webdriverio/webdriverio/issues/999/events","html_url":"https://github.com/webdriverio/webdriverio/issues/999","id":125640332,"number":999,"title":"Standardise return value for `browser.executeAsync`","user":{"login":"georgecrawford","id":84737,"avatar_url":"https://avatars.githubusercontent.com/u/84737?v=3","gravatar_id":"","url":"https://api.github.com/users/georgecrawford","html_url":"https://github.com/georgecrawford","followers_url":"https://api.github.com/users/georgecrawford/followers","following_url":"https://api.github.com/users/georgecrawford/following{/other_user}","gists_url":"https://api.github.com/users/georgecrawford/gists{/gist_id}","starred_url":"https://api.github.com/users/georgecrawford/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/georgecrawford/subscriptions","organizations_url":"https://api.github.com/users/georgecrawford/orgs","repos_url":"https://api.github.com/users/georgecrawford/repos","events_url":"https://api.github.com/users/georgecrawford/events{/privacy}","received_events_url":"https://api.github.com/users/georgecrawford/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/webdriverio/webdriverio/labels/Discussion","name":"Discussion","color":"207de5"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":13,"created_at":"2016-01-08T16:09:54Z","updated_at":"2016-01-12T18:33:51Z","closed_at":null,"body":"In my tests, I'm using this pattern when I need to run `browser.executeAsync`:\r\n```js\r\nconst result = browser.executeAsync(function(param, done) {\r\n\tsetTimeout(function() {\r\n\t\tconst result = getResult();\r\n\t\tif (result) {\r\n\t\t\tdone([null, result]);\r\n\t\t} else {\r\n\t\t\tdone(['getResult() failed because...']);\r\n\t\t}\r\n\t}, 1000);\r\n});\r\nreturn checkAsyncResult(result)\r\n\r\nfunction checkAsyncResult(result) {\r\n\tif (!result || !Array.isArray(result.value)) {\r\n\t\tthrow Error(`Unexpected reponse from executeAsync: ${JSON.stringify(result.value)}`);\r\n\t}\r\n\r\n\tif (result.value[0]) {\r\n\t\tthrow result.value[0];\r\n\t}\r\n\r\n\treturn result.value[1];\r\n};\r\n```\r\nIt'd be quite nice if webdriverio could do this automatically, and we could standardise on the `[(err), res]` format for async responses. It's somewhat related to the idea of making WebElement JSON objects first-class citizens."},"comment":{"url":"https://api.github.com/repos/webdriverio/webdriverio/issues/comments/171004644","html_url":"https://github.com/webdriverio/webdriverio/issues/999#issuecomment-171004644","issue_url":"https://api.github.com/repos/webdriverio/webdriverio/issues/999","id":171004644,"user":{"login":"georgecrawford","id":84737,"avatar_url":"https://avatars.githubusercontent.com/u/84737?v=3","gravatar_id":"","url":"https://api.github.com/users/georgecrawford","html_url":"https://github.com/georgecrawford","followers_url":"https://api.github.com/users/georgecrawford/followers","following_url":"https://api.github.com/users/georgecrawford/following{/other_user}","gists_url":"https://api.github.com/users/georgecrawford/gists{/gist_id}","starred_url":"https://api.github.com/users/georgecrawford/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/georgecrawford/subscriptions","organizations_url":"https://api.github.com/users/georgecrawford/orgs","repos_url":"https://api.github.com/users/georgecrawford/repos","events_url":"https://api.github.com/users/georgecrawford/events{/privacy}","received_events_url":"https://api.github.com/users/georgecrawford/received_events","type":"User","site_admin":false},"created_at":"2016-01-12T18:33:51Z","updated_at":"2016-01-12T18:33:51Z","body":"How?"}}