You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+6Lines changed: 6 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -274,11 +274,15 @@ Notes:
274
274
* Some of the classes implement `IDisposable` interface and should be correctly disposed.
275
275
* Be cautious when caching types that implement `IDisposable` interface as the values will not be automatically disposed by the caches.
276
276
* Be cautious when using classes with `LazyThreadSafetyMode.PublicationOnly` behavior together with `IDisposable` types as discarded instances will not be disposed.
277
+
*`PublicationOnly` implementations may run multiple factories concurrently and publish the first successful result.
278
+
* Async lazy and initializer methods throw `InvalidOperationException` if a factory returns a null `Task`.
277
279
278
280
#### Lazy
279
281
280
282
Two different implementations of async lazy values are available — `LazyAsyncPublicationOnly` and `LazyAsyncExecutionAndPublication`. Those are async versions of `System.Lazy` class with `LazyThreadSafetyMode.PublicationOnly` and `LazyThreadSafetyMode.ExecutionAndPublication` modes respectively. The reason that async lazy implementations are separate classes is that `LazyAsyncExecutionAndPublication` implements `IDisposable` due to its usage of an instance of `SemaphoreSlim` whereas `LazyAsyncPublicationOnly` does not need to implement `IDisposable`.
281
283
284
+
`LazyAsyncExecutionAndPublication` runs at most one in-flight factory and retries after failed or canceled attempts. `LazyAsyncPublicationOnly` may execute multiple concurrent factories, but only the first successfully published value is retained.
285
+
282
286
```csharp
283
287
usingLibSharp.Caching;
284
288
@@ -309,6 +313,8 @@ Two different implementations of async lazy values are available — `LazyAsyncP
309
313
310
314
Initializers in LibSharp are equivalents of lazy types, with the only difference being that the value factory is provided at lazy initialization time instead of creation time. They also enable cases where different factories can be used to initialize the value, where only one will succeed at setting the value.
311
315
316
+
`InitializerAsyncExecutionAndPublication` runs at most one in-flight factory and retries after failed or canceled attempts. `InitializerAsyncPublicationOnly` may execute multiple concurrent factories, but only the first successfully published value is retained.
Copy file name to clipboardExpand all lines: src/LibSharp/Caching/InitializerAsyncPublicationOnly.cs
+5-1Lines changed: 5 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,11 @@ namespace LibSharp.Caching;
11
11
/// Async initializer with LazyThreadSafetyMode.PublicationOnly.
12
12
/// </summary>
13
13
/// <typeparam name="T">Value type.</typeparam>
14
-
/// <remarks>Should not be used with IDisposable or IAsyncDisposable value types since it does not dispose of values.</remarks>
14
+
/// <remarks>
15
+
/// Should not be used with IDisposable or IAsyncDisposable value types since it does not dispose of values.
16
+
/// Concurrent callers may execute different factories more than once; only the first successfully published value is retained and returned to all callers.
17
+
/// Faulted or canceled attempts are not cached and may be retried by later callers.
/// <exception cref="OperationCanceledException">Thrown if <paramref name="cancellationToken"/> is canceled before a published value is produced.</exception>
52
+
/// <exception cref="InvalidOperationException">Thrown if the value factory returns a null task.</exception>
0 commit comments