Skip to content

Instantly share code, notes, and snippets.

@joakin
Created August 9, 2017 09:00
Show Gist options
  • Save joakin/229492684c84a4839e14de225e3948ff to your computer and use it in GitHub Desktop.
Save joakin/229492684c84a4839e14de225e3948ff to your computer and use it in GitHub Desktop.
Sync w/ promises to async function
/*
* 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