0
const Future = require('fibers/future')
function myfunc() {
    var future = new Future();
    Eos().getInfo((err, res) => {
        future["return"]=res;
    })
    return future.wait();
};
console.log(myfunc());

The Error is can't wait without a fiber please help me with this

yash vadhvani
  • 329
  • 2
  • 12
  • Can you try this? var fn = async function() { Eos().getInfo((err, res) => { return res; }) }.future(); var future = await fn(); future.wait(); – Shriram Manoharan Aug 07 '18 at 09:06
  • 1
    `future.return` is a function, so you should call it, not overwrite it (`future.return(res);`). In the recent versions of JS, promises and async/await are easier to use, in my opinion. – MasterAM Aug 07 '18 at 10:20

2 Answers2

0

As the error states a future can only "wait" if it is ran within a fiber

console.log(Fiber(myfunc).run());
Zack Newsham
  • 2,810
  • 1
  • 23
  • 43
0

Get rid of this with promises.

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);
    });
yash vadhvani
  • 329
  • 2
  • 12