From 04536f6088ba03e7a7fa16ed5da9fe08cb3abcc5 Mon Sep 17 00:00:00 2001 From: Nathan Phillip Brink Date: Mon, 2 Jan 2017 00:41:46 -0500 Subject: [PATCH] Call cleanup correctly (without arguments). Fixes #9. --- index.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 4911df7..dac83c3 100644 --- a/index.js +++ b/index.js @@ -21,7 +21,12 @@ module.exports.withFile = function withFile(fn) { cleanup = o.cleanup; delete o.cleanup; return fn(o); - }).finally(cleanup); + }).finally(function () { + // May not pass any arguments to cleanup() or it fails. + if (cleanup) { + cleanup(); + } + }); }; @@ -44,7 +49,12 @@ module.exports.withDir = function withDir(fn) { cleanup = o.cleanup; delete o.cleanup; return fn(o); - }).finally(cleanup); + }).finally(function () { + // May not pass any arguments to cleanup() or it fails. + if (cleanup) { + cleanup(); + } + }); };