/**
* files [ 'Orthogroups.txt', 'pfam_final.txt', 'txt.txt', 'txt2.txt' ]
/
files.forEach(async file => {
const filrdir: string = path.join(TXTFilesPath, file);
if (file !== 'txt.txt' && file !== 'txt2.txt') {
return;
}
fs.stat(filrdir, (err, stats) => {
if (err) {
console.error(err);
return;
}
if (stats.isFile()) {
// 创建一个文件流
const inStream = fs.createReadStream(filrdir);
const rl = readline.createInterface(inStream);
console.log('filrdir', filrdir);
// 开始解析操作
rl.on('line', async line => {
const fastaName = line.split(':')[0];
const idList = line.split(':')[1];
let temList = idList.trim().split(' ');
temList = [...new Set(temList)];
try {
await temList.forEach((ele: string) => {
this.proteinObject[ele] = fastaName;
});
} catch (e) {
console.error(e);
}
});
}
});
});
files 是一个长度为 4 的数组,然后后面 filrdir 是能建立 txt.txt 与 txt2.txt 两个文件流的,但是最后 this.proteinObject 却始终只存储了一个文件的内容。我知道是异步的原因导致的,但是还是不理解。希望哪个大哥解解惑
* files [ 'Orthogroups.txt', 'pfam_final.txt', 'txt.txt', 'txt2.txt' ]
/
files.forEach(async file => {
const filrdir: string = path.join(TXTFilesPath, file);
if (file !== 'txt.txt' && file !== 'txt2.txt') {
return;
}
fs.stat(filrdir, (err, stats) => {
if (err) {
console.error(err);
return;
}
if (stats.isFile()) {
// 创建一个文件流
const inStream = fs.createReadStream(filrdir);
const rl = readline.createInterface(inStream);
console.log('filrdir', filrdir);
// 开始解析操作
rl.on('line', async line => {
const fastaName = line.split(':')[0];
const idList = line.split(':')[1];
let temList = idList.trim().split(' ');
temList = [...new Set(temList)];
try {
await temList.forEach((ele: string) => {
this.proteinObject[ele] = fastaName;
});
} catch (e) {
console.error(e);
}
});
}
});
});
files 是一个长度为 4 的数组,然后后面 filrdir 是能建立 txt.txt 与 txt2.txt 两个文件流的,但是最后 this.proteinObject 却始终只存储了一个文件的内容。我知道是异步的原因导致的,但是还是不理解。希望哪个大哥解解惑