nicomen / mojo-useragent-cached

Mojo::UserAgent::Cached - Caching, Non-blocking I/O HTTP, Local file and WebSocket user agent
3 stars 2 forks source link

Handle finish events on transactions returned from cache #1

Closed mavit closed 3 years ago

mavit commented 3 years ago

Mojo::Transaction has a finish event which can be subscribed to to trigger a callback when the transaction completes. Because Mojo::UserAgent::Cached creates a new transaction containing the cached response, such a callback is only called when content is fetched, not when returned from cache.

This commit fixes it so that the finish callback is called even for transactions returning cached responses.

This seems to be sufficient for my use case (which is Mojo::UserAgent::Role::Queued). More work would be required to support other events, such as the finish events on req and res.

mavit commented 3 years ago

I simply hadn't given any thought to what would be required to support req and res, since I have no need for them myself.

But yes, it seems straightforward to support them too, so I've pushed a version that does.

nicomen commented 3 years ago

Great, thanks!