Created
August 9, 2017 09:00
-
-
Save joakin/229492684c84a4839e14de225e3948ff to your computer and use it in GitHub Desktop.
Sync w/ promises to async function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Get disambiguation links for a given page | |
* @param {!Request} req | |
* @return {!BBPromise} | |
*/ | |
- function getDisambiguationLinks(req) { | |
+ async function getDisambiguationLinks(req) { | |
const p = req.params; | |
const query = { | |
action: 'query', | |
titles: p.title, | |
prop: 'links', | |
format: 'json', | |
formatversion: '2' | |
}; | |
- return apiUtil.mwApiGet(app, p.domain, query).then((resp) => { | |
- const result = resp.body; | |
- const page = result && result.query && result.query.pages && result.query.pages[0]; | |
- const links = page && page.links; | |
- if (links) { | |
- return links.map((page)=>page.title); | |
- } else { | |
- return []; | |
- } | |
- }); | |
+ const resp = await apiUtil.mwApiGet(app, p.domain, query) | |
+ const result = resp.body; | |
+ const page = result && result.query && result.query.pages && result.query.pages[0]; | |
+ const links = page && page.links; | |
+ if (links) { | |
+ return links.map((page)=>page.title); | |
+ } else { | |
+ return []; | |
+ } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment