问题
我目前遇到一个问题,就是$bus.$on监听 this.$bus.$on('wirteInterface',this.wirteInterface)。我这边监听是受到一个消息,就调用一次wirteInterface函数。而我的wirteInterface函数需要用到fs写入内容到文件里。这样导致这个函数如果被同时多次调用,就会导致同时多次操作文件,导致文件被占用,不知道用谁先写入后写入。
源代码如下:
this.$bus.$on('wirteInterface',this.wirteInterface)
async wirteInterface(params){
await this.GTwriteCodeFile(
'interface',
false,
params,
obj.code
)
await this.GTwriteCodeFile(
'api',
false,
params,
obj.apiCode
)
}
这边的GTWriteCodeFile是我封装的一个文件写入函数。异步执行的。
如果多次调用wirteInterface则会同时多次处理文件,导