diff --git a/lib/tmp.js b/lib/tmp.js index 53994c1..7f66201 100644 --- a/lib/tmp.js +++ b/lib/tmp.js @@ -421,16 +421,17 @@ function _prepareTmpDirRemoveCallback(name, opts) { function _prepareRemoveCallback(removeFunction, arg) { var called = false; - return function _cleanupCallback() { - if (called) return; + return function _cleanupCallback(next) { + if (!called) { + var index = _removeObjects.indexOf(_cleanupCallback); + if (index >= 0) { + _removeObjects.splice(index, 1); + } - var index = _removeObjects.indexOf(_cleanupCallback); - if (index >= 0) { - _removeObjects.splice(index, 1); + called = true; + removeFunction(arg); } - - called = true; - removeFunction(arg); + if (next) next(null); }; }