Add async support to gitlab-http
What does this MR do and why?
After the initial implementation of the gitlab-http
gem (#415686 (closed)), we'll add the async
support to it. Related to #427701 (closed).
When using the gitlab-http
gem, you can pass the async: true
option
and get a LazyResponse
object. Since there is no business
logic and external connection inside the async calls, it is thread-safe.
Screenshots or screen recordings
locations = [
'https://hub.dummyapis.com/delay?seconds=1',
'https://hub.dummyapis.com/delay?seconds=2',
'https://hub.dummyapis.com/delay?seconds=3',
'https://hub.dummyapis.com/delay?seconds=4',
'https://hub.dummyapis.com/delay?seconds=5'
]; nil
promises = locations.map do |location|
Gitlab::HTTP_V2.get(location, async: true)
end; nil
promises.each(&:execute).each(&:wait); nil
puts promises.map(&:value).map(&:body)
After ~5 seconds, you'll see this;
This response has been delayed for 1 seconds
This response has been delayed for 2 seconds
This response has been delayed for 3 seconds
This response has been delayed for 4 seconds
This response has been delayed for 5 seconds
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Edited by Furkan Ayhan