{"action":"opened","number":1232,"pull_request":{"url":"https://api.github.com/repos/facebook/react-native/pulls/1232","id":35111397,"html_url":"https://github.com/facebook/react-native/pull/1232","diff_url":"https://github.com/facebook/react-native/pull/1232.diff","patch_url":"https://github.com/facebook/react-native/pull/1232.patch","issue_url":"https://api.github.com/repos/facebook/react-native/issues/1232","number":1232,"state":"open","locked":false,"title":"[RFC][Bridge] Add support for JS async functions, backed by RCT_EXPORT_PROMISE","user":{"login":"ide","id":379606,"avatar_url":"https://avatars.githubusercontent.com/u/379606?v=3","gravatar_id":"","url":"https://api.github.com/users/ide","html_url":"https://github.com/ide","followers_url":"https://api.github.com/users/ide/followers","following_url":"https://api.github.com/users/ide/following{/other_user}","gists_url":"https://api.github.com/users/ide/gists{/gist_id}","starred_url":"https://api.github.com/users/ide/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ide/subscriptions","organizations_url":"https://api.github.com/users/ide/orgs","repos_url":"https://api.github.com/users/ide/repos","events_url":"https://api.github.com/users/ide/events{/privacy}","received_events_url":"https://api.github.com/users/ide/received_events","type":"User","site_admin":false},"body":"Adds support for JS async methods and helps guide people writing native modules w.r.t. the callbacks. With this diff, on the native side you write:\r\n\r\n```objc\r\nRCT_EXPORT_PROMISE(getValueAsync:(NSString *)key)\r\n{\r\n  NSError *error = nil;\r\n  id value = [_nativeDataStore valueForKey:key error:&error];\r\n\r\n  // \"resolve\" and \"reject\" are automatically defined blocks that take\r\n  // any object (nil is OK) and an NSError, respectively\r\n  if (!error) {\r\n    resolve(value);\r\n  } else {\r\n    reject(error);\r\n  }\r\n}\r\n```\r\n\r\nOn the JS side, you can write:\r\n\r\n```js\r\nvar {DemoDataStore} = require('react-native').NativeModules;\r\nDemoDataStore.getValueAsync('sample-key').then((value) => {\r\n  console.log('Got:', value);\r\n}, (error) => {\r\n  console.error(error);\r\n  // \"error\" is an Error object whose message is the NSError's description.\r\n  // The NSError's code and domain are also set, and the native trace is\r\n  // available under\r\n});\r\n```\r\n\r\nAnd if you take a time machine or use Babel w/stage 1, you can write:\r\n\r\n```js\r\ntry {\r\n  var value = await DemoDataStore.getValueAsync('sample-key');\r\n  console.log('Got:', value);\r\n} catch (error) {\r\n  console.error(error);\r\n}\r\n```\r\n\r\nFor now the macro is defined as RCT_EXPORT_PROMISE_EXPERIMENTAL since I'd like to merge this and get real-world feedback on the API before committing to it.\r\n\r\nFixes #172\r\nMakes #186 less relevant","created_at":"2015-05-11T09:38:55Z","updated_at":"2015-05-11T09:38:55Z","closed_at":null,"merged_at":null,"merge_commit_sha":null,"assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/facebook/react-native/pulls/1232/commits","review_comments_url":"https://api.github.com/repos/facebook/react-native/pulls/1232/comments","review_comment_url":"https://api.github.com/repos/facebook/react-native/pulls/comments{/number}","comments_url":"https://api.github.com/repos/facebook/react-native/issues/1232/comments","statuses_url":"https://api.github.com/repos/facebook/react-native/statuses/0cdcfab65c554597f325e7ffe991013f00404f5b","head":{"label":"ide:promise-methods","ref":"promise-methods","sha":"0cdcfab65c554597f325e7ffe991013f00404f5b","user":{"login":"ide","id":379606,"avatar_url":"https://avatars.githubusercontent.com/u/379606?v=3","gravatar_id":"","url":"https://api.github.com/users/ide","html_url":"https://github.com/ide","followers_url":"https://api.github.com/users/ide/followers","following_url":"https://api.github.com/users/ide/following{/other_user}","gists_url":"https://api.github.com/users/ide/gists{/gist_id}","starred_url":"https://api.github.com/users/ide/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ide/subscriptions","organizations_url":"https://api.github.com/users/ide/orgs","repos_url":"https://api.github.com/users/ide/repos","events_url":"https://api.github.com/users/ide/events{/privacy}","received_events_url":"https://api.github.com/users/ide/received_events","type":"User","site_admin":false},"repo":{"id":32947292,"name":"react-native","full_name":"ide/react-native","owner":{"login":"ide","id":379606,"avatar_url":"https://avatars.githubusercontent.com/u/379606?v=3","gravatar_id":"","url":"https://api.github.com/users/ide","html_url":"https://github.com/ide","followers_url":"https://api.github.com/users/ide/followers","following_url":"https://api.github.com/users/ide/following{/other_user}","gists_url":"https://api.github.com/users/ide/gists{/gist_id}","starred_url":"https://api.github.com/users/ide/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ide/subscriptions","organizations_url":"https://api.github.com/users/ide/orgs","repos_url":"https://api.github.com/users/ide/repos","events_url":"https://api.github.com/users/ide/events{/privacy}","received_events_url":"https://api.github.com/users/ide/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ide/react-native","description":"A framework for building native apps with React.","fork":true,"url":"https://api.github.com/repos/ide/react-native","forks_url":"https://api.github.com/repos/ide/react-native/forks","keys_url":"https://api.github.com/repos/ide/react-native/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ide/react-native/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ide/react-native/teams","hooks_url":"https://api.github.com/repos/ide/react-native/hooks","issue_events_url":"https://api.github.com/repos/ide/react-native/issues/events{/number}","events_url":"https://api.github.com/repos/ide/react-native/events","assignees_url":"https://api.github.com/repos/ide/react-native/assignees{/user}","branches_url":"https://api.github.com/repos/ide/react-native/branches{/branch}","tags_url":"https://api.github.com/repos/ide/react-native/tags","blobs_url":"https://api.github.com/repos/ide/react-native/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ide/react-native/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ide/react-native/git/refs{/sha}","trees_url":"https://api.github.com/repos/ide/react-native/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ide/react-native/statuses/{sha}","languages_url":"https://api.github.com/repos/ide/react-native/languages","stargazers_url":"https://api.github.com/repos/ide/react-native/stargazers","contributors_url":"https://api.github.com/repos/ide/react-native/contributors","subscribers_url":"https://api.github.com/repos/ide/react-native/subscribers","subscription_url":"https://api.github.com/repos/ide/react-native/subscription","commits_url":"https://api.github.com/repos/ide/react-native/commits{/sha}","git_commits_url":"https://api.github.com/repos/ide/react-native/git/commits{/sha}","comments_url":"https://api.github.com/repos/ide/react-native/comments{/number}","issue_comment_url":"https://api.github.com/repos/ide/react-native/issues/comments{/number}","contents_url":"https://api.github.com/repos/ide/react-native/contents/{+path}","compare_url":"https://api.github.com/repos/ide/react-native/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ide/react-native/merges","archive_url":"https://api.github.com/repos/ide/react-native/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ide/react-native/downloads","issues_url":"https://api.github.com/repos/ide/react-native/issues{/number}","pulls_url":"https://api.github.com/repos/ide/react-native/pulls{/number}","milestones_url":"https://api.github.com/repos/ide/react-native/milestones{/number}","notifications_url":"https://api.github.com/repos/ide/react-native/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ide/react-native/labels{/name}","releases_url":"https://api.github.com/repos/ide/react-native/releases{/id}","created_at":"2015-03-26T19:20:50Z","updated_at":"2015-05-08T11:34:44Z","pushed_at":"2015-05-11T09:35:07Z","git_url":"git://github.com/ide/react-native.git","ssh_url":"git@github.com:ide/react-native.git","clone_url":"https://github.com/ide/react-native.git","svn_url":"https://github.com/ide/react-native","homepage":"http://facebook.github.io/react-native/","size":11573,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"facebook:master","ref":"master","sha":"120c32c52cd606214e5d497de40ff2454657b4f7","user":{"login":"facebook","id":69631,"avatar_url":"https://avatars.githubusercontent.com/u/69631?v=3","gravatar_id":"","url":"https://api.github.com/users/facebook","html_url":"https://github.com/facebook","followers_url":"https://api.github.com/users/facebook/followers","following_url":"https://api.github.com/users/facebook/following{/other_user}","gists_url":"https://api.github.com/users/facebook/gists{/gist_id}","starred_url":"https://api.github.com/users/facebook/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/facebook/subscriptions","organizations_url":"https://api.github.com/users/facebook/orgs","repos_url":"https://api.github.com/users/facebook/repos","events_url":"https://api.github.com/users/facebook/events{/privacy}","received_events_url":"https://api.github.com/users/facebook/received_events","type":"Organization","site_admin":false},"repo":{"id":29028775,"name":"react-native","full_name":"facebook/react-native","owner":{"login":"facebook","id":69631,"avatar_url":"https://avatars.githubusercontent.com/u/69631?v=3","gravatar_id":"","url":"https://api.github.com/users/facebook","html_url":"https://github.com/facebook","followers_url":"https://api.github.com/users/facebook/followers","following_url":"https://api.github.com/users/facebook/following{/other_user}","gists_url":"https://api.github.com/users/facebook/gists{/gist_id}","starred_url":"https://api.github.com/users/facebook/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/facebook/subscriptions","organizations_url":"https://api.github.com/users/facebook/orgs","repos_url":"https://api.github.com/users/facebook/repos","events_url":"https://api.github.com/users/facebook/events{/privacy}","received_events_url":"https://api.github.com/users/facebook/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/facebook/react-native","description":"A framework for building native apps with React.","fork":false,"url":"https://api.github.com/repos/facebook/react-native","forks_url":"https://api.github.com/repos/facebook/react-native/forks","keys_url":"https://api.github.com/repos/facebook/react-native/keys{/key_id}","collaborators_url":"https://api.github.com/repos/facebook/react-native/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/facebook/react-native/teams","hooks_url":"https://api.github.com/repos/facebook/react-native/hooks","issue_events_url":"https://api.github.com/repos/facebook/react-native/issues/events{/number}","events_url":"https://api.github.com/repos/facebook/react-native/events","assignees_url":"https://api.github.com/repos/facebook/react-native/assignees{/user}","branches_url":"https://api.github.com/repos/facebook/react-native/branches{/branch}","tags_url":"https://api.github.com/repos/facebook/react-native/tags","blobs_url":"https://api.github.com/repos/facebook/react-native/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/facebook/react-native/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/facebook/react-native/git/refs{/sha}","trees_url":"https://api.github.com/repos/facebook/react-native/git/trees{/sha}","statuses_url":"https://api.github.com/repos/facebook/react-native/statuses/{sha}","languages_url":"https://api.github.com/repos/facebook/react-native/languages","stargazers_url":"https://api.github.com/repos/facebook/react-native/stargazers","contributors_url":"https://api.github.com/repos/facebook/react-native/contributors","subscribers_url":"https://api.github.com/repos/facebook/react-native/subscribers","subscription_url":"https://api.github.com/repos/facebook/react-native/subscription","commits_url":"https://api.github.com/repos/facebook/react-native/commits{/sha}","git_commits_url":"https://api.github.com/repos/facebook/react-native/git/commits{/sha}","comments_url":"https://api.github.com/repos/facebook/react-native/comments{/number}","issue_comment_url":"https://api.github.com/repos/facebook/react-native/issues/comments{/number}","contents_url":"https://api.github.com/repos/facebook/react-native/contents/{+path}","compare_url":"https://api.github.com/repos/facebook/react-native/compare/{base}...{head}","merges_url":"https://api.github.com/repos/facebook/react-native/merges","archive_url":"https://api.github.com/repos/facebook/react-native/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/facebook/react-native/downloads","issues_url":"https://api.github.com/repos/facebook/react-native/issues{/number}","pulls_url":"https://api.github.com/repos/facebook/react-native/pulls{/number}","milestones_url":"https://api.github.com/repos/facebook/react-native/milestones{/number}","notifications_url":"https://api.github.com/repos/facebook/react-native/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/facebook/react-native/labels{/name}","releases_url":"https://api.github.com/repos/facebook/react-native/releases{/id}","created_at":"2015-01-09T18:10:16Z","updated_at":"2015-05-11T09:28:40Z","pushed_at":"2015-05-11T09:38:55Z","git_url":"git://github.com/facebook/react-native.git","ssh_url":"git@github.com:facebook/react-native.git","clone_url":"https://github.com/facebook/react-native.git","svn_url":"https://github.com/facebook/react-native","homepage":"http://facebook.github.io/react-native/","size":31747,"stargazers_count":13763,"watchers_count":13763,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":1515,"mirror_url":null,"open_issues_count":439,"forks":1515,"open_issues":439,"watchers":13763,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/facebook/react-native/pulls/1232"},"html":{"href":"https://github.com/facebook/react-native/pull/1232"},"issue":{"href":"https://api.github.com/repos/facebook/react-native/issues/1232"},"comments":{"href":"https://api.github.com/repos/facebook/react-native/issues/1232/comments"},"review_comments":{"href":"https://api.github.com/repos/facebook/react-native/pulls/1232/comments"},"review_comment":{"href":"https://api.github.com/repos/facebook/react-native/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/facebook/react-native/pulls/1232/commits"},"statuses":{"href":"https://api.github.com/repos/facebook/react-native/statuses/0cdcfab65c554597f325e7ffe991013f00404f5b"}},"merged":false,"mergeable":null,"mergeable_state":"unknown","merged_by":null,"comments":0,"review_comments":0,"commits":1,"additions":229,"deletions":28,"changed_files":6}}