Skip to content

Instantly share code, notes, and snippets.

@agniswarm
Created September 22, 2018 08:01
Show Gist options
  • Save agniswarm/0d8b1c6e38e7f9502468544acbae1735 to your computer and use it in GitHub Desktop.
Save agniswarm/0d8b1c6e38e7f9502468544acbae1735 to your computer and use it in GitHub Desktop.
Turn requestjs into a async and await style function
import request from 'request';
async function requested(params: any) {
let promise = await new Promise<any>((resolve, reject) => {
request(params, (err: any, res: any, body: any) => {
if (err || res.statusCode != 200)
reject(err)
else
resolve(body);
})
})
return promise;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment