我是NodeJS的新手。我有一个异步功能
request({url: 'url',json: true}, function (error, response, body) {});
Run Code Online (Sandbox Code Playgroud)
我只想在调用此函数后才调用该函数。我在这里不能叫.then()。这种情况下还有哪些其他选择?
小智 6
你可以尝试这样的事情
return new Promise(resolve => {
request({
url: "",
method: "",
headers: {},
json: true
}, function (error, response, body) {
if(!error)
resolve(body);
})
}).then(value => {
// process value here
})
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5193 次 |
| 最近记录: |