Skip to content

Add ActionScopeListener#3668

Merged
JGulbronson merged 1 commit intocashapp:masterfrom
JGulbronson:jgulbronson.add-ActionScopeListener
Feb 12, 2026
Merged

Add ActionScopeListener#3668
JGulbronson merged 1 commit intocashapp:masterfrom
JGulbronson:jgulbronson.add-ActionScopeListener

Conversation

@JGulbronson
Copy link
Collaborator

ActionScopeListener allows developers to hook in to the close() method of ActionScope, and perform actions immediately before the scope is closed. For example, you could buffer logs while the scope is open, and then dedupe and flush them before it's closed. Currently ActionScopeListener only supports onClose(), but in the future could support onEnter() as well.

@@ -110,9 +110,9 @@ inline fun <reified T : Any> keyOf(a: KClass<out Annotation>?): Key<T> = keyOf(a
*/
inline fun <reified T : Any> keyOf(qualifier: BindingQualifier? = null): Key<T> =
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realized while using keyOf in my tests that this didn't support parameterized types properly, which IMO seems like a bit of a footgun.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch

@JGulbronson JGulbronson force-pushed the jgulbronson.add-ActionScopeListener branch from 6ed4b99 to c9c8ee6 Compare February 11, 2026 13:38
Copy link
Collaborator

@adrw adrw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LG

`ActionScopeListener` allows developers to hook in to the `close()` method of `ActionScope`, and perform actions immediately before the scope is closed. For example, you could buffer logs while the scope is open, and then dedupe and flush them before it's closed. Currently `ActionScopeListener` only supports `onClose()`, but in the future could support `onEnter()` as well.
@JGulbronson JGulbronson force-pushed the jgulbronson.add-ActionScopeListener branch from c9c8ee6 to a77496e Compare February 11, 2026 13:51
@JGulbronson JGulbronson requested a review from adrw February 11, 2026 14:05
Copy link
Contributor

@Nava2 Nava2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking comments :)

override fun close() {
threadLocalInstance.remove()
try {
listeners.get().forEach { it.onClose() }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a concern if any of these throw? Should each be wrapped in a try..catch and log errors?

Copy link
Collaborator Author

@JGulbronson JGulbronson Feb 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I considered that, but didn't want to indiscriminately catch exceptions if the developer actually wants their exception to propagate. I did keep the finally though so that we don't forget to clean up the ThreadLocal.

* For example: an action-scoped HTTP Request Body may still be transmitting to the client despite the scope being
* closed.
*/
fun onClose()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the scope being closed be passed into the listener?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally you're not using the ActionScope directly, you're dealing with ActionScoped<T>. If they need it, they can just inject ActionScope in to their listener, but I don't expect many to usages to need it.

@JGulbronson JGulbronson requested a review from Nava2 February 11, 2026 14:36
Copy link
Collaborator

@adrw adrw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LG

@JGulbronson JGulbronson added this pull request to the merge queue Feb 12, 2026
Merged via the queue into cashapp:master with commit fae6a0b Feb 12, 2026
14 checks passed
@JGulbronson JGulbronson deleted the jgulbronson.add-ActionScopeListener branch February 12, 2026 14:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Comments