-
Notifications
You must be signed in to change notification settings - Fork 213
Add ActionScopeListener #3668
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 ActionScopeListener #3668
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| package misk.scope | ||
|
|
||
| /** | ||
| * A listener that can be called at various points within an [ActionScope]'s lifecycle. See the comment on each method | ||
| * to understand when in the lifecycle it is called. | ||
| */ | ||
| interface ActionScopeListener { | ||
| /** | ||
| * Called during [ActionScope.close], immediately before the [ThreadLocal] that holds the [ActionScope.Instance] is | ||
| * removed. | ||
| * | ||
| * The [ActionScope] is not closed until all the listeners are executed. That means that: | ||
| * - Immediately before [onClose] is called, [ActionScope.inScope] returns true | ||
| * - During [onClose], [ActionScope.inScope] returns true | ||
| * - Immediately after all listeners have called [onClose], [ActionScope.inScope] returns false | ||
| * | ||
| * The [ActionScope] being closed or not is independent of the lifecycle of any action scoped values. A reference to | ||
| * an object provided by an [ActionScopedProvider] can be held and used even if [ActionScope.inScope] returns false. | ||
| * For example: an action-scoped HTTP Request Body may still be transmitting to the client despite the scope being | ||
| * closed. | ||
| */ | ||
| fun onClose() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should the scope being closed be passed into the listener?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Generally you're not using the |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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> = | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I realized while using
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch |
||
| when (qualifier) { | ||
| is BindingQualifier.InstanceQualifier -> Key.get(T::class.java, qualifier.annotation) | ||
| is BindingQualifier.TypeClassifier -> Key.get(T::class.java, qualifier.type.java) | ||
| null -> Key.get(T::class.java) | ||
| is BindingQualifier.InstanceQualifier -> Key.get(object : TypeLiteral<T>() {}, qualifier.annotation) | ||
| is BindingQualifier.TypeClassifier -> Key.get(object : TypeLiteral<T>() {}, qualifier.type.java) | ||
| null -> Key.get(object : TypeLiteral<T>() {}) | ||
| } | ||
|
|
||
| /** | ||
|
|
||
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.
Is there a concern if any of these throw? Should each be wrapped in a
try..catchand log errors?Uh oh!
There was an error while loading. Please reload this page.
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 considered that, but didn't want to indiscriminately catch exceptions if the developer actually wants their exception to propagate. I did keep the
finallythough so that we don't forget to clean up theThreadLocal.