Update README.md to emphasize async nature of response streaming#15
Merged
astuyve merged 1 commit intoastuyve:mainfrom Aug 19, 2024
Merged
Update README.md to emphasize async nature of response streaming#15astuyve merged 1 commit intoastuyve:mainfrom
astuyve merged 1 commit intoastuyve:mainfrom
Conversation
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 returns by the provided handler, this means that the lambda would only output values that were fed into the stream imperatively inside the handler function. Anything that happens asynchronously would not be captured. The solution to this is to use a promise that only resolves once the potential asynchronous work has been completed.
Owner
|
Yup, thanks. Sorry I missed this for so long, my notifications are a disaster. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In the original example, the response stream was being filled before
myHandlerfinished 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.For example:
☝️ 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.