summaryrefslogtreecommitdiff
path: root/lib/ensureAsync.js
diff options
context:
space:
mode:
authorAlex Early <alexander.early@gmail.com>2018-07-08 16:58:36 -0700
committerGitHub <noreply@github.com>2018-07-08 16:58:36 -0700
commite4751178540a3c6e64598b93977481ec599704d2 (patch)
treedce5731bdb1076971d2e4a0a42fbe0d95c720185 /lib/ensureAsync.js
parent6405b109fe60541ff42d7638ac891d321d6a7bb3 (diff)
downloadasync-e4751178540a3c6e64598b93977481ec599704d2.tar.gz
ES6-ify codebase (#1553)
* cancelable foreach * cancelable waterfall * cancellable auto * fix lint * fix tests * cancelable whilst/until/during/forever * fix waterfall test. It WILL get there * docs * use rest params instead of slice * clean up internals * remove property func * clarify uses of createTester * happy path async funtions in asyncify * stop using arguments * DLL to class * moar arrows * fix merge issues * remove forOwn * moar arrows * fix merge mistake * even more arrows, what can stop him * mo more fn.apply(null,...) * remove more spurious uses of apply * update lint config * just when you thought there couldn't possibly be more arrows * use eslint:recommended * even less uses or aguments * get rid of prototype cuteness * fix concat tests * fix more tests
Diffstat (limited to 'lib/ensureAsync.js')
-rw-r--r--lib/ensureAsync.js15
1 files changed, 6 insertions, 9 deletions
diff --git a/lib/ensureAsync.js b/lib/ensureAsync.js
index a579efc..b2b35b9 100644
--- a/lib/ensureAsync.js
+++ b/lib/ensureAsync.js
@@ -1,5 +1,4 @@
import setImmediate from './internal/setImmediate';
-import initialParams from './internal/initialParams';
import { isAsync } from './internal/wrapAsync';
/**
@@ -39,19 +38,17 @@ import { isAsync } from './internal/wrapAsync';
*/
export default function ensureAsync(fn) {
if (isAsync(fn)) return fn;
- return initialParams(function (args, callback) {
+ return function (...args/*, callback*/) {
+ var callback = args.pop()
var sync = true;
- args.push(function () {
- var innerArgs = arguments;
+ args.push((...innerArgs) => {
if (sync) {
- setImmediate(function () {
- callback.apply(null, innerArgs);
- });
+ setImmediate(() => callback(...innerArgs));
} else {
- callback.apply(null, innerArgs);
+ callback(...innerArgs);
}
});
fn.apply(this, args);
sync = false;
- });
+ };
}