-
Notifications
You must be signed in to change notification settings - Fork 138
Add a RequestQueue #412
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a RequestQueue #412
Conversation
ddc0233 to
77809cc
Compare
glbrntt
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the queue has some surprising behaviour that should be changed or at least made much clearer.
| self.generalPurposeQueue.isEmpty | ||
| } | ||
|
|
||
| mutating func count(for eventLoop: EventLoop?) -> Int { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think as a user I'd be very surprised that getting the count is mutating and potentially allocates!
Perhaps there should be a non-mutating version of withEventLoopQueue, something like:
func withEventLoopQueueIfAvailable<Result>(
for eventLoopID: EventLoopID,
_ closure: (CircularBuffer<Request>) -> Result
) -> Result?| return self.generalPurposeQueue.count | ||
| } | ||
|
|
||
| mutating func isEmpty(for eventLoop: EventLoop?) -> Bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here re: mutating
|
|
||
| mutating func removeAll() -> [Request] { | ||
| var result = [Request]() | ||
| result = self.eventLoopQueues.reduce(into: result) { partialResult, element in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this just eventLoopQueues.flatMap { $1 }?
| self.generalPurposeQueue.forEach { request in | ||
| result.append(request) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use result.append(contentsOf: self.generalPurposeQueue) to avoid intermediate reallocs of result
Sources/AsyncHTTPClient/ConnectionPool/State Machine/HTTPConnectionPool+RequestQueue.swift
Show resolved
Hide resolved
| import NIOEmbedded | ||
|
|
||
| /// An `EventLoopGroup` of `EmbeddedEventLoop`s. | ||
| final class EmbeddedEventLoopGroup: EventLoopGroup { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What a great idea!
| var count: Int { | ||
| self.generalPurposeQueue.count | ||
| } | ||
|
|
||
| var isEmpty: Bool { | ||
| self.generalPurposeQueue.isEmpty | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is surprising behaviour I think -- I would expect the count to return the total count and isEmpty to only return true if both queues are empty.
| } | ||
| } | ||
|
|
||
| func __testOnly_internal_value() -> HTTPSchedulableRequest { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: "wrapped request" or similar would be clearer than internal_value
glbrntt
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good modulo a couple of nits
| self.count = 0 | ||
| } | ||
|
|
||
| private(set) var count: Int |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How often is this used externally? If it's not used frequently then dynamically computing this would be better I think...
| if self.eventLoopQueues[eventLoopID] != nil { | ||
| return closure(self.eventLoopQueues[eventLoopID]!) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: avoid hashing twice here (also we can avoid the bang)
glbrntt
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Motivation
For our Connection Pool we need to queue requests.
Changes
Waitertype... Not needed anymore.RequestboxRequestQueueResult
Less code in the actual state machine.