\$\begingroup\$
\$\endgroup\$
I'm trying to figure out the most elegant solution to do the following asynchronously using JavaScript (specifically node):
- Given a destination file name, check if it is a directory
- If it is a directory, delete it
- Copy a source file onto the destination file name
I would like to do this asynchronously using callbacks.
Here is what I have come up with:
var preCopyOp = fs.lstatSync(dstFilename).isDirectory() ?
function(callback) {
rimraf(dstFilename, callback)
} :
function(callback) {
callback();
};
preCopyOp(function() {
ncp(srcFilename, dstFilename, function(err) {
if(err) {
return console.error(err);
}
});
});
The no-op passthrough function seems like a bit of a kludge to me. Is there a more elegant way to do this?
200_success
145k22 gold badges190 silver badges478 bronze badges
1 Answer 1
\$\begingroup\$
\$\endgroup\$
0
You can write
function(callback) {
callback();
}
as just
callback
answered Feb 26, 2015 at 2:40
Explore related questions
See similar questions with these tags.
default