nats-io / nats-server

High-Performance server for NATS.io, the cloud and edge native messaging system.
https://nats.io
Apache License 2.0
16.03k stars 1.41k forks source link

Refactor delayed API responses #5955

Closed kozlovic closed 1 month ago

kozlovic commented 1 month ago

This is similar to @neilalexander PR (#5948) but has a slightly different approach. We use the struct to have a next so that we can use a list since the list will be maintained ordered. The for-loop is in one level, as opposed to two, which means that pushing to the IPQ will be "immediately" popped, even if we have a timer initialized and waiting to fire. The timer is reset (not recreated everytime) only if the added response ends-up being at the head of the list.

Added a test that verifies that it works properly.

Signed-off-by: Ivan Kozlovic ivan@synadia.com

neilalexander commented 1 month ago

Rebased on top of main.

derekcollison commented 1 month ago

This one ready?