async function testSync() {
var result = await new Promise(function (resolve) {
test(function (result) {
resolve(result);
});
});
return result;
}
function test(callback) {
setTimeout(callback, 1000);
}
async function run() {
console.log(1);
var r = await testSync();
console.log(r)
console.log(3);
}
run();
I successfully made two functions. One async and one sync, however I am forced to put testSync() in async function.
But running node modules function fs.readfilesync()
, for example, I do not have to do
that. Can someone explain why and how i can make sync functions, like
fs does it?