| | | 1 | | // ----------------------------------------------------------------------- |
| | | 2 | | // <copyright file="ImmediateCollectionSynchronizer.cs" company="Stéphane ANDRE"> |
| | | 3 | | // Copyright (c) Stéphane ANDRE. All rights reserved. |
| | | 4 | | // </copyright> |
| | | 5 | | // ----------------------------------------------------------------------- |
| | | 6 | | |
| | | 7 | | using System; |
| | | 8 | | |
| | | 9 | | namespace MyNet.Collections; |
| | | 10 | | |
| | | 11 | | /// <summary> |
| | | 12 | | /// Current collection synchronizer that performs no synchronization, for use when thread safety is not required. |
| | | 13 | | /// </summary> |
| | | 14 | | public sealed class ImmediateCollectionSynchronizer : ICollectionSynchronizer |
| | | 15 | | { |
| | | 16 | | /// <summary> |
| | | 17 | | /// Gets the default instance of the collection synchronizer that performs no synchronization. |
| | | 18 | | /// </summary> |
| | 3 | 19 | | public static ImmediateCollectionSynchronizer Default { get; } = new(); |
| | | 20 | | |
| | | 21 | | /// <summary> |
| | | 22 | | /// Initializes a new instance of the <see cref="ImmediateCollectionSynchronizer"/> class. |
| | | 23 | | /// </summary> |
| | 3 | 24 | | private ImmediateCollectionSynchronizer() { } |
| | | 25 | | |
| | | 26 | | /// <summary> |
| | | 27 | | /// Executes the specified action without any synchronization, as this implementation does not provide thread safety |
| | | 28 | | /// </summary> |
| | | 29 | | /// <param name="action">The action to execute.</param> |
| | 21 | 30 | | public void Write(Action action) => action(); |
| | | 31 | | |
| | | 32 | | /// <summary> |
| | | 33 | | /// Executes the specified function without any synchronization, as this implementation does not provide thread safe |
| | | 34 | | /// </summary> |
| | | 35 | | /// <typeparam name="TResult">The type of the result.</typeparam> |
| | | 36 | | /// <param name="func">The function to execute.</param> |
| | | 37 | | /// <returns>The result of the function.</returns> |
| | 9 | 38 | | public TResult Write<TResult>(Func<TResult> func) => func(); |
| | | 39 | | |
| | | 40 | | /// <summary> |
| | | 41 | | /// Executes the specified action without any synchronization, as this implementation does not provide thread safety |
| | | 42 | | /// </summary> |
| | | 43 | | /// <param name="action">The action to execute.</param> |
| | 9 | 44 | | public void Read(Action action) => action(); |
| | | 45 | | |
| | | 46 | | /// <summary> |
| | | 47 | | /// Executes the specified function without any synchronization, as this implementation does not provide thread safe |
| | | 48 | | /// </summary> |
| | | 49 | | /// <typeparam name="TResult">The type of the result.</typeparam> |
| | | 50 | | /// <param name="func">The function to execute.</param> |
| | | 51 | | /// <returns>The result of the function.</returns> |
| | 21 | 52 | | public TResult Read<TResult>(Func<TResult> func) => func(); |
| | | 53 | | } |
| | | 54 | | |