Turn any callback into promise with babel-plugin-promise

briefly,I will tell you how to convert an existing callback to promise.

We will need to use babel.

For example, let’s take a request from npm and convert it to a promise

yarn add babel-plugin-promise --dev
require("babel-polyfill");

import request from "request";

//@promisify req
__ = request(arg1);

console.log(req("http://www.google.com"));

req("http://www.google.com")
    .then(res => console.log(res.body.length))
    .catch(err => console.log(err));

let’s check

quite quickly

babel-plugin-promise

The Practical Developer稿源:The Practical Developer (源链) | 关于 | 阅读提示

本站遵循[CC BY-NC-SA 4.0]。如您有版权、意见投诉等问题,请通过eMail联系我们处理。
酷辣虫 » 综合编程 » Turn any callback into promise with babel-plugin-promise

喜欢 (0)or分享给?

专业 x 专注 x 聚合 x 分享 CC BY-NC-SA 4.0

使用声明 | 英豪名录