Skip to content

Instantly share code, notes, and snippets.

@dimpiax
Created March 5, 2017 22:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dimpiax/a2cae08deeda1ded806384705b958d37 to your computer and use it in GitHub Desktop.
Save dimpiax/a2cae08deeda1ded806384705b958d37 to your computer and use it in GitHub Desktop.
request library with promise wrapped under ES6 with flowtype
/* @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