How do I wait for readFile () to return the result before executing?

  node.js, question
var fs =require('fs')
 var co = require('co');
 
 function readfile(path){
 fs.readFile(path,'utf8',(err,data)=>{
 if(err) console.log(err);
 return data;
 });
 bracket
 
 
 var gen =function* (){
 
 var f1=yield readfile('/home/kevin/nodeSrc/testSrc/file/a.js');
 var f2=yield readfile('/home/kevin/nodeSrc/testSrc/file/b.js');
 console.log(f1.toString());
 console.log(f2.toString());
 };
 
 
 
 co(gen).then(function(){
 console.log('111');
 });

The above code should read all the files, but did not return the results, so there are a few doubts, please consult you
1. Why not report the mistake?
2.lz single takereadfile()Methods The reason why the experiment was carried out was becausereadFile()It is asynchronous in itself, soFIA Formula 1 World ChampionshipThe value of isundefined, but that should also be able to continue to carry out ah, why don’t you have a little print information?
3. How to change to read and display the printed information?

Lz beginner, please give directions

1. Why not report the mistake? Even if readFile is wrong, it is also an asynchronous error, and you cannot get it.
2. You did not use the generator correctly.
3. yield accepts a Promise object, so the change is as follows:

function readfile(path) {
 return new Promise((resolve, reject) => {
 fs.readFile(path, 'utf8', (err, data) => {
 if (err) {
 console.log(err);
 reject(err);
 bracket
 resolve(data);
 });
 });
 bracket