-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
async
function support
#1390
async
function support
#1390
Changes from 8 commits
9fc2995
77e6a21
ac0bdd0
ffd6685
db9face
0bae58f
22a5354
cdbc105
4b1278b
e62c53c
700aa23
57b8877
6ac9cb0
faf395c
94a8b2d
fab1e45
8faed87
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,27 +4,29 @@ node_js: | |
- "0.10" | ||
- "0.12" | ||
- "4" | ||
- "6" | ||
- "7" | ||
|
||
matrix: | ||
include: | ||
- node_js: "6" | ||
addons: | ||
firefox: "49.0" | ||
env: BROWSER=true MAKE_TEST=true | ||
#matrix: | ||
# include: | ||
# - node_js: "6" | ||
# addons: | ||
# firefox: "49.0" | ||
# env: BROWSER=true MAKE_TEST=true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why are we disabling this stuff? Can we just up the firefox version? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I disabled this thinking it was an issue with karma, but it's a syntax error. I'll investigate further and re-enable. We could test both 45 (ESR, no |
||
env: | ||
matrix: BROWSER=false MAKE_TEST=false | ||
|
||
after_success: npm run coveralls | ||
|
||
# Needed to run Karma with Firefox on Travis | ||
# http://karma-runner.github.io/0.13/plus/travis.html | ||
before_script: | ||
- export DISPLAY=:99.0 | ||
- sh -e /etc/init.d/xvfb start | ||
#before_script: | ||
# - export DISPLAY=:99.0 | ||
# - sh -e /etc/init.d/xvfb start | ||
|
||
script: | ||
- npm test | ||
# ensure buildable | ||
- "[ $MAKE_TEST == false ] || make" | ||
# test in firefox | ||
- "[ $BROWSER == false ] || npm run mocha-browser-test" | ||
- "[ $BROWSER == false ] || npm run mocha-browser-test" |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,7 +48,7 @@ import initialParams from './internal/initialParams'; | |
* } | ||
* ], callback); | ||
* | ||
* // es6 example | ||
* // es2017 example | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it be useful to add a note here that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, we should clarify here. |
||
* var q = async.queue(async.asyncify(async function(file) { | ||
* var intermediateStep = await processFile(file); | ||
* return await somePromise(intermediateStep) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,8 +3,10 @@ import forOwn from 'lodash/_baseForOwn'; | |
import arrayMap from 'lodash/_arrayMap'; | ||
import isArray from 'lodash/isArray'; | ||
import trim from 'lodash/trim'; | ||
import wrapAsync from './internal/wrapAsync'; | ||
import { isAsync } from './internal/wrapAsync'; | ||
|
||
var FN_ARGS = /^(function)?\s*[^\(]*\(\s*([^\)]*)\)/m; | ||
var FN_ARGS = /^(?:async\s+)?(function)?\s*[^\(]*\(\s*([^\)]*)\)/m; | ||
var FN_ARG_SPLIT = /,/; | ||
var FN_ARG = /(=.+)?(\s*)$/; | ||
var STRIP_COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg; | ||
|
@@ -106,22 +108,25 @@ export default function autoInject(tasks, callback) { | |
|
||
forOwn(tasks, function (taskFn, key) { | ||
var params; | ||
var fnIsAsync = isAsync(taskFn); | ||
|
||
if (isArray(taskFn)) { | ||
params = taskFn.slice(0, -1); | ||
taskFn = taskFn[taskFn.length - 1]; | ||
|
||
newTasks[key] = params.concat(params.length > 0 ? newTask : taskFn); | ||
} else if (taskFn.length === 1) { | ||
} else if ((!fnIsAsync && taskFn.length === 1) || | ||
(fnIsAsync && taskFn.length === 0)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤢 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, I should probably factor this condition out into a |
||
// no dependencies, use the function as-is | ||
newTasks[key] = taskFn; | ||
} else { | ||
params = parseParams(taskFn); | ||
if (taskFn.length === 0 && params.length === 0) { | ||
if (taskFn.length === 0 && !fnIsAsync && params.length === 0) { | ||
throw new Error("autoInject task functions require explicit parameters."); | ||
} | ||
|
||
params.pop(); | ||
// remove callback param | ||
if (!fnIsAsync) params.pop(); | ||
|
||
newTasks[key] = params.concat(newTask); | ||
} | ||
|
@@ -131,7 +136,7 @@ export default function autoInject(tasks, callback) { | |
return results[name]; | ||
}); | ||
newArgs.push(taskCb); | ||
taskFn.apply(null, newArgs); | ||
wrapAsync(taskFn).apply(null, newArgs); | ||
} | ||
}); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is es8? can we set this to 2017/2018 whatever?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ES8 is eslint's shorthand for ES2017. No, you can't use "2017"... Just subtract 2009. 😛