const Future = require('fibers/future')
function myfunc() {
var future = new Future();
Eos().getInfo((err, res) => {
future["return"]=res;
})
return future.wait();
};
console.log(myfunc());
错误是不能等待没有光纤请帮我解决这个问题
const Future = require('fibers/future')
function myfunc() {
var future = new Future();
Eos().getInfo((err, res) => {
future["return"]=res;
})
return future.wait();
};
console.log(myfunc());
错误是不能等待没有光纤请帮我解决这个问题
正如错误所述,如果未来在光纤内运行,则只能“等待”
console.log(Fiber(myfunc).run());
用承诺摆脱这个。
function myfunc() {
return new Promise((resolve, reject) => {
Eos().getInfo((err, res) => {
if (err) {
reject(err);
}
else {
resolve(res);
}
});
});
}
myfunc()
.then((res) => {
console.log(res);
})
.catch(err => {
console.log(err);
});