Create HTTP requests on a background queue. #720
Merged
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.
This refactors the internal implementation of the
sendData
to createthe HTTP requests on a new background queue. Note that this simply changes
the creation of the request to the new background queue - the actual
execution was already on a background thread.
Previously, the creation would happen on the queueing thread. This
means that while the HTTP request was being created, events would not be
queued. By default, this is not a problem, the actual creation of the
request is a few milliseconds at most. However, this assumes that the request
factory customers might set only runs for a few milliseconds. A long running request
factory would have a chance of blocking the queueing thread for too long and
open a small window for data loss.
With this change, customers to add more complex logic in their request
factories. e.g. a customer can use the request factory to fetch a
token for a user, and attach that token to the request being made to by
the library to their proxy.
How should this be manually tested?
This is already being tested by the existing code paths. I also manually tested by adding a few logging statements https://cloudup.com/chrCiBv2E_f.
You'll see that in between the factory being invoked (which is faking a slow factory by sleeping) and the request being done, the library was able to queue messages.
Any background context you want to provide?
Internal Doc: https://paper.dropbox.com/doc/poHde883uCtEZwJ8MDGwH
@segmentio/gateway