@@ -9,6 +9,7 @@ import okio.Buffer
9
9
import okio.ByteString
10
10
import okio.EOFException
11
11
import kotlin.LazyThreadSafetyMode.PUBLICATION
12
+ import kotlin.concurrent.Volatile
12
13
import kotlin.jvm.JvmMultifileClass
13
14
import kotlin.jvm.JvmName
14
15
import kotlin.reflect.KClass
@@ -58,6 +59,17 @@ public class WorkflowIdentifier internal constructor(
58
59
59
60
private val proxiedIdentifiers = generateSequence(this ) { it.proxiedIdentifier }
60
61
62
+ @Volatile
63
+ private var cachedToString: String? = null
64
+
65
+ /* *
66
+ * Either a [KClass] or [KType] representing the "real" type that this identifier
67
+ * identifies – i.e. which is not an [ImpostorWorkflow].
68
+ */
69
+ public val realType: WorkflowIdentifierType by lazy(PUBLICATION ) {
70
+ proxiedIdentifiers.last().type
71
+ }
72
+
61
73
/* *
62
74
* If this identifier is snapshottable, returns the serialized form of the identifier.
63
75
* If it is not snapshottable, returns null.
@@ -83,23 +95,26 @@ public class WorkflowIdentifier internal constructor(
83
95
}
84
96
}
85
97
86
- /* *
87
- * Returns either a [KClass] or [KType] representing the "real" type that this identifier
88
- * identifies – i.e. which is not an [ImpostorWorkflow].
89
- */
90
- public fun getRealIdentifierType (): WorkflowIdentifierType = proxiedIdentifiers.last().type
98
+ @Deprecated(" This is now a lazily computed val" , ReplaceWith (" realType" ))
99
+ public fun getRealIdentifierType (): WorkflowIdentifierType = realType
91
100
92
101
/* *
93
102
* If this identifier identifies an [ImpostorWorkflow], returns the result of that workflow's
94
103
* [ImpostorWorkflow.describeRealIdentifier] method, otherwise returns a description of this
95
104
* identifier including the name of its workflow type and any [ImpostorWorkflow.realIdentifier]s.
96
105
*
97
106
*/
98
- override fun toString (): String =
99
- description?.invoke()
100
- ? : proxiedIdentifiers
101
- .joinToString { it.typeName }
102
- .let { " WorkflowIdentifier($it )" }
107
+ override fun toString (): String {
108
+ return cachedToString ? : (
109
+ description?.invoke()
110
+ ? : proxiedIdentifiers
111
+ .joinToString { it.typeName }
112
+ .let { " WorkflowIdentifier($it )" }
113
+ )
114
+ .also {
115
+ cachedToString = it
116
+ }
117
+ }
103
118
104
119
override fun equals (other : Any? ): Boolean = when {
105
120
this == = other -> true
0 commit comments