diff --git a/.eslintrc b/.eslintrc index 80fa6bf..a849e12 100644 --- a/.eslintrc +++ b/.eslintrc @@ -2,10 +2,10 @@ // ╔═╗╔═╗╦ ╦╔╗╔╔╦╗┬─┐┌─┐ // ║╣ ╚═╗║ ║║║║ ║ ├┬┘│ // o╚═╝╚═╝╩═╝╩╝╚╝ ╩ ┴└─└─┘ - // A set of basic conventions (similar to .jshintrc) for use within any - // arbitrary JavaScript / Node.js package -- inside or outside Sails.js. - // For the master copy of this file, see the `.eslintrc` template file in - // the `sails-generate` package (https://www.npmjs.com/package/sails-generate.) + // A set of basic conventions for use within any arbitrary Node.js package -- + // inside or outside the Sails framework. For the master copy of this file, + // see the `.eslintrc` template file in the `sails-generate` package + // (https://www.npmjs.com/package/sails-generate.) // Designed for ESLint v4. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // For more information about any of the rules below, check out the relevant @@ -19,8 +19,7 @@ }, "parserOptions": { - "ecmaVersion": 5 - // ^^This can be changed to `8` if this package doesn't need to support <= Node v6. + "ecmaVersion": 8 }, "globals": { @@ -29,10 +28,11 @@ }, "rules": { + "block-scoped-var": ["error"], "callback-return": ["error", ["done", "proceed", "next", "onwards", "callback", "cb"]], "camelcase": ["warn", {"properties": "always"}], "comma-style": ["warn", "last"], - "curly": ["error"], + "curly": ["warn"], "eqeqeq": ["error", "always"], "eol-last": ["warn"], "handle-callback-err": ["error"], @@ -62,8 +62,9 @@ "no-unused-vars": ["warn", {"caughtErrors":"all", "caughtErrorsIgnorePattern": "^unused($|[A-Z].*$)", "argsIgnorePattern": "^unused($|[A-Z].*$)", "varsIgnorePattern": "^unused($|[A-Z].*$)" }], "no-use-before-define": ["error", {"functions":false}], "one-var": ["warn", "never"], + "prefer-arrow-callback": ["warn", {"allowNamedFunctions":false}], "quotes": ["warn", "single", {"avoidEscape":false, "allowTemplateLiterals":true}], - "semi": ["error", "always"], + "semi": ["warn", "always"], "semi-spacing": ["warn", {"before":false, "after":true}], "semi-style": ["warn", "last"] } diff --git a/lib/parley.js b/lib/parley.js index 7a8aa98..9f04f30 100644 --- a/lib/parley.js +++ b/lib/parley.js @@ -199,7 +199,7 @@ module.exports = function parley(handleExec, explicitCbMaybe, customMethods, tim // If appropriate, start the 15 second .exec() countdown. var EXEC_COUNTDOWN_IN_SECONDS = 15; if (IS_DEBUG_OR_NON_PRODUCTION_ENV) { - π._execCountdown = setTimeout(function(){ + π._execCountdown = setTimeout(()=>{ // IWMIH, it means that this Deferred hasn't begun executing, // even after 15 seconds. This deserves a warning log. // > See https://trello.com/c/7QnQZ6aC for more background. @@ -350,16 +350,17 @@ module.exports = function parley(handleExec, explicitCbMaybe, customMethods, tim };//ƒ - +// FUTURE: finish this: +// // /** // * parley.callable() // * // * Build a simple function which returns a Deferred object. // * > This is a shortcut for building simple functions when you don't need the // * > full customizability of calling parley() to build a Deferred for you on the -// * > fly (e.g. b/c you don't care about support chain-ability) +// * > fly (e.g. b/c as an implementor, you don't care about having custom +// * > chainable methods) // * -// * CURRENTLY EXPERIMENTAL! // * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // * @param {AsyncFunction} gracefullyHandleExec // * @param {Number?} timeout @@ -367,25 +368,31 @@ module.exports = function parley(handleExec, explicitCbMaybe, customMethods, tim // * // * @returns {Function} // */ -// module.exports.callable = function(gracefullyHandleExec, timeout, omen){ - -// console.warn('WARNING: parley.callable() is currently experimental and should not be relied upon.'); +// module.exports.callable = function(gracefullyHandleExec, timeoutMaybe, omenMaybe){ // if (!_.isFunction(gracefullyHandleExec) || gracefullyHandleExec.constructor.name !== 'AsyncFunction') { -// throw new Error('parley.callable() expects an async function (e.g. `async ()=>{}`) to be provided as the first argument. Instead, got: '+require('util').inspect(gracefullyHandleExec)); +// throw new Error('parley.callable() expects an async function (e.g. `async ()=>{}`) to be provided as the first argument. Instead, got: '+util.inspect(gracefullyHandleExec, {depth:5})); // }//• // return function handleCalling(/*…*/) { +// // ^Note that this function is _deliberately_ NOT an arrow function, so that +// // we can use `this` and `arguments` to simulate gracefullyHandleExec being +// // called exactly as-is. (In most cases, this should not matter. But +// // packages are sometimes used in mysterious, eclectic ways.) +// // +// // Also note that we name this function (handleCalling) so that we can +// // reference it below when we build an omen. + // var parley = module.exports; -// var returnedFnArguments = arguments; -// var returnedFnCtx = this;//« should really never matter, we just do it this way for consistency +// var newCallableFnArguments = arguments; +// var newCallableFnCtx = this;//« should really never matter, we just do it this way for consistency // omen = omen || flaverr.omen(handleCalling); -// return parley(function(done) { -// gracefullyHandleExec.apply(returnedFnCtx, returnedFnArguments) -// .then(function(result) { -// done(undefined, result); +// return parley((done)=>{ +// gracefullyHandleExec.apply(newCallableFnCtx, newCallableFnArguments) +// .then((resultMaybe)=>{ +// done(undefined, resultMaybe); // }) -// .catch(function(err) { +// .catch((err)=>{ // done(err); // }); // }, undefined, undefined, timeout, omen, undefined); diff --git a/lib/private/Deferred.js b/lib/private/Deferred.js index 303d186..8c1e325 100644 --- a/lib/private/Deferred.js +++ b/lib/private/Deferred.js @@ -221,7 +221,7 @@ Deferred.prototype.exec = function(_cb, handleUncaughtException){ // > Also note that we include a worst-case-scenario spinlock here (but it should never fire!) var timeoutAlarm; if (self._timeout && self._timeout > 0) { - timeoutAlarm = setTimeout(function(){ + timeoutAlarm = setTimeout(()=>{ if (self._hasFinishedExecuting) { console.warn( 'WARNING: Consistency violation: Trying to trigger timeout, but execution has\n'+ @@ -589,7 +589,7 @@ Deferred.prototype.now = function () { var isFinishedExecuting; var immediateResult; var immediateError; - this.exec(function (err, result){ + this.exec((err, result)=>{ isFinishedExecuting = true; immediateError = err; immediateResult = result; @@ -649,7 +649,7 @@ Deferred.prototype.log = function (){ console.log('Running with `.log()`...'); } - this.exec(function(err, result) { + this.exec((err, result)=>{ if (err) { console.error(); console.error('- - - - - - - - - - - - - - - - - - - - - - - -'); @@ -954,13 +954,13 @@ function proceedToInterceptsAndChecks (errCbArg, resultCbArg, extraCbArgs, self, try { lcPromise = matchingUserlandLC.handler(errCbArg); } catch (err) { return proceed(err); } - lcPromise.then(function(resultFromHandler){ + lcPromise.then((resultFromHandler)=>{ proceed(undefined, resultFromHandler); - }).catch(function(err){ + }).catch((err)=>{ proceed(err); });//_∏_ } - })(function(err, resultFromHandler){ + })((err, resultFromHandler)=>{ // Clear spinlock. self._hasStartedButNotFinishedAfterExecLC = false; diff --git a/package.json b/package.json index f50a9b2..0c1ecdb 100644 --- a/package.json +++ b/package.json @@ -34,5 +34,8 @@ "benchmark": "2.1.2", "eslint": "4.19.1", "mocha": "6.1.3" + }, + "engines": { + "node": ">=8" } }