diff options
author | JT Turner <jtwebman@gmail.com> | 2016-04-03 19:48:29 -0700 |
---|---|---|
committer | JT Turner <jtwebman@gmail.com> | 2016-04-03 20:20:20 -0700 |
commit | 53ca8e1756e432321928cc4fefb7b96ee685af96 (patch) | |
tree | ed4c1ea24c05bd1604907a55047ef00d18553173 /lib/reflect.js | |
parent | 283f5083f47c42f459bb07f20f48fda9f724fffa (diff) | |
download | async-53ca8e1756e432321928cc4fefb7b96ee685af96.tar.gz |
Add back reflect and reflectAll.
Diffstat (limited to 'lib/reflect.js')
-rw-r--r-- | lib/reflect.js | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/lib/reflect.js b/lib/reflect.js new file mode 100644 index 0000000..53cfa44 --- /dev/null +++ b/lib/reflect.js @@ -0,0 +1,29 @@ +'use strict'; + +export default function reflect(fn) { + return function reflectOn() { + var args = Array.prototype.slice.call(arguments); + var reflectCallback = args.pop(); + + args.push(function callback(err) { + if (err) { + reflectCallback(null, { + error: err + }); + } else { + var cbArgs = Array.prototype.slice.call(arguments, 1); + var value = null; + if (cbArgs.length === 1) { + value = cbArgs[0]; + } else if (cbArgs.length > 1) { + value = cbArgs; + } + reflectCallback(null, { + value: value + }); + } + }); + + return fn.apply(this, args); + }; +} |