function smartPromise(promise){
	return promise.then(res=>([null,res])).catch((e)=>([e,null]));
}

async function task(){
  const [errorA,fileA] = await smartPromise(readFileA());
    if(errorA!==null){
        return 'read file A error';
    }
  const [errorB,fileB] = await smartPromise(readFileB());
    if(errorB!==null){
        return 'read file B error';
    }
    return fileB
}

 

posted on 2021-03-25 18:36  jzfan  阅读(55)  评论(0编辑  收藏  举报