grunt.file.write(.....) 是同步的还是异步的?
Is grunt.file.write(.....) synchronous or asynchronous?
我有一个代码,其中我是 运行 一个使用
异步执行的繁重任务
var done = this.async();
在代码的某处,我正在写入一个文件,然后按如下方式调用回调:
grunt.fie.write(<necessary arguments>);
callback(null);
我的问题是,会不会出现在grunt.write写入文件完成之前调用回调的情况?如果是这样,我该如何避免这种情况?
P.S. I want to use grunt.file.write and not 'fs' module.
谢谢
查看source,可以看到它使用了fs.writeFileSync
"under the covers",所以是同步的。
同步。
从第 295 行开始 the source code:
if (!nowrite) {
fs.writeFileSync(filepath, contents);
}
我有一个代码,其中我是 运行 一个使用
异步执行的繁重任务var done = this.async();
在代码的某处,我正在写入一个文件,然后按如下方式调用回调:
grunt.fie.write(<necessary arguments>);
callback(null);
我的问题是,会不会出现在grunt.write写入文件完成之前调用回调的情况?如果是这样,我该如何避免这种情况?
P.S. I want to use grunt.file.write and not 'fs' module.
谢谢
查看source,可以看到它使用了fs.writeFileSync
"under the covers",所以是同步的。
同步。
从第 295 行开始 the source code:
if (!nowrite) {
fs.writeFileSync(filepath, contents);
}