| | | 1 | | namespace AsyncResponse; |
| | | 2 | | |
| | | 3 | | /// <summary> |
| | | 4 | | /// Expression markers for registering recoverable lost-subscriber callbacks with compile-time safety. |
| | | 5 | | /// Use them inside the lambda passed to <c>OnLostSubscriberResume</c>/<c>OnLostSubscriberFailure</c> |
| | | 6 | | /// to mark which arguments the runtime should substitute when the callback fires: |
| | | 7 | | /// <code> |
| | | 8 | | /// recoverableBuilder.For<OrderResult>(correlationId) |
| | | 9 | | /// .OnLostSubscriberResume<IOrderFlow>(flow => |
| | | 10 | | /// flow.ResumeAsync(orderId, Placeholder.Payload<OrderResult>(), Placeholder.CorrelationId( |
| | | 11 | | /// </code> |
| | | 12 | | /// The marker methods are never executed; they only exist inside expression trees and throw if |
| | | 13 | | /// invoked directly. |
| | | 14 | | /// </summary> |
| | | 15 | | public static class Placeholder |
| | | 16 | | { |
| | | 17 | | /// <summary>Marks an argument to be replaced by the response payload at invocation time.</summary> |
| | 2 | 18 | | public static TPayload Payload<TPayload>() => throw MarkerInvoked(); |
| | | 19 | | |
| | | 20 | | /// <summary>Marks an argument to be replaced by the exception at invocation time.</summary> |
| | 2 | 21 | | public static Exception Exception() => throw MarkerInvoked(); |
| | | 22 | | |
| | | 23 | | /// <summary>Marks an argument to be replaced by the correlation id at invocation time.</summary> |
| | 2 | 24 | | public static string CorrelationId() => throw MarkerInvoked(); |
| | | 25 | | |
| | | 26 | | private static InvalidOperationException MarkerInvoked() |
| | 3 | 27 | | => new("Placeholder methods are expression-tree markers and must not be invoked at runtime. " + |
| | 3 | 28 | | "Use them only inside OnLostSubscriberResume/OnLostSubscriberFailure lambdas."); |
| | | 29 | | } |