Created
September 22, 2018 08:01
-
-
Save agniswarm/0d8b1c6e38e7f9502468544acbae1735 to your computer and use it in GitHub Desktop.
Turn requestjs into a async and await style function
This file contains 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
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