Suggestion: Make middleware pipeline async with promises #238
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.
Summary
To address some of the problems with hosting bolt as a serverless function (#220)
For example, in AWS Lambda, we must not call res.end() until the very end of our flow. This is due to https calls forcefully terminating after we ack with a response. The middleware pipeline needs to be async in order for us to know when bolt is finished with the event.
Another issue I haven't addressed in this PR is the fact that the receiver is using Node's EventEmitter class. The
emit
method does not return a promise or take a callback, so we won't be able to know when the serverless function can ack. My personal solution was to write a custom receiver using emittery, which provides an emitter that returns a promise. I feel like this is a bad practice however, and there is probably a better way to process an event in a way that's safe to run inside a serverless handler.Using the changes in my forked repo, I was able to get a bolt-powered endpoint working in Zeit Now, which is powered by AWS Lambda.
Requirements (place an
x
in each[ ]
)