In the original example, the response stream was being filled before myHandler finished executing.
Since the non-AWS proxy in streamifyResponseawaits on the void promise returned by the provided handler, this means that the lambda would only output values that were fed into the stream imperatively during the scope of the handler function. Anything that happens asynchronously would not be captured.
:point_up: Here, we don't return a promise. So the response resolved by the lambda will simply be "Hello", because the proxy won't wait for the async write of "World".
The solution to this is to use a promise that only resolves once the potential asynchronous work has been completed. (See the proposed changes of this PR)
Might as well update the readme to direct people towards that.
In the original example, the response stream was being filled before
myHandler
finished executing.Since the non-AWS proxy in
streamifyResponse
awaits on the void promise returned by the provided handler, this means that the lambda would only output values that were fed into the stream imperatively during the scope of the handler function. Anything that happens asynchronously would not be captured.For example:
:point_up: Here, we don't return a promise. So the response resolved by the lambda will simply be "Hello", because the proxy won't wait for the async write of "World".
The solution to this is to use a promise that only resolves once the potential asynchronous work has been completed. (See the proposed changes of this PR)
Might as well update the readme to direct people towards that.