Created
March 5, 2017 22:12
-
-
Save dimpiax/a2cae08deeda1ded806384705b958d37 to your computer and use it in GitHub Desktop.
request library with promise wrapped under ES6 with flowtype
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
/* @flow */ | |
import request from 'request' | |
const promiseWrapper = (r: request): ((data: any) => Promise<Object>) => | |
(data: any): Promise<Object> => new Promise((resolve: any, reject: any) => { | |
r(data, (error: any, response: any, body: any) => { | |
if (error) reject(error) | |
else resolve(body) | |
}) | |
}) | |
const prequest = promiseWrapper(request) | |
export default prequest | |
export { | |
request, | |
promiseWrapper | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment