@@ -104,6 +104,9 @@ public ValueTask<T> GetOrCreateAsync<T>(
104
104
IEnumerable < string > ? tags = null ,
105
105
CancellationToken cancellationToken = default )
106
106
{
107
+ // It is *not* an error that this Clear occurs before the "await"; by definition, the implementation is *required* to copy
108
+ // the value locally before an await, precisely because the ref-struct cannot bridge an await. Thus: we are fine to clean
109
+ // the buffer even in the non-synchronous completion scenario.
107
110
ValueTask < T > result = GetOrCreateAsync ( key . Text , factory , WrappedCallbackCache < T > . Instance , options , tags , cancellationToken ) ;
108
111
key . Clear ( ) ;
109
112
return result ;
@@ -129,17 +132,12 @@ public ValueTask<T> GetOrCreateAsync<TState, T>(
129
132
IEnumerable < string > ? tags = null ,
130
133
CancellationToken cancellationToken = default )
131
134
{
132
- try
133
- {
134
- return GetOrCreateAsync ( key . Text , state , factory , options , tags , cancellationToken ) ;
135
- }
136
- finally
137
- {
138
- // It is *not* an error that this Clear occurs before the "await"; by definition, the implementation is *required* to copy
139
- // the value locally before an await, precisely because the ref-struct cannot bridge an await. Thus: we are fine to clean
140
- // the buffer even in the non-synchronous completion scenario.
141
- key . Clear ( ) ;
142
- }
135
+ // It is *not* an error that this Clear occurs before the "await"; by definition, the implementation is *required* to copy
136
+ // the value locally before an await, precisely because the ref-struct cannot bridge an await. Thus: we are fine to clean
137
+ // the buffer even in the non-synchronous completion scenario.
138
+ ValueTask < T > result = GetOrCreateAsync ( key . Text , state , factory , options , tags , cancellationToken ) ;
139
+ key . Clear ( ) ;
140
+ return result ;
143
141
}
144
142
#endif
145
143
0 commit comments