Add support for async wrapped handlers - #23
Conversation
|
I guess the difference between this and #22 is that this does not require a different mechanism for executing the wrapper (via |
|
Could you pls add a test for a case when I use a callback at async handler, see: PS: nobody force me to get rid of a callback in case of async handler. In other words, you never know does function use callback or not. |
|
@dhm116 Thanks for the PR. Included in lambda-wrapper 0.3.0 |
|
@Enase that scenario you're describing would be mixing promises and callbacks, which is never recommended anyhow - I don't mind creating a follow-up PR with additional test coverage around that scenario if others think it would be beneficial... |
|
@mpuittinen I totally agree with you. but in a real life code is written using async handlers for nodejs6.10. Most of people just changed babel config options and now we have async handlers that use callbacks. My goal is just to point you on a trouble. Just imagine how many people will copy paste the example from serverless blog or Serverless Node.js Starter and many and many other places. |
|
@Enase true, the blog / starter may drive people to "bad" practices. Since it's just a question of test cases (no code changes on the actual modules), I've added those. |
This adds some basic support for Node v8 in that it will check if there was a returned result from the wrapped handler and, if that result is also a promise, it will avoid the scenario of returning nested promises.
I tried to add some test coverage that seemed to follow a similar pattern as to the existing tests, but they should only execute when tested with node v8 or up (as they rely upon the async/await features).