You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by bl...@apache.org on 2022/12/08 13:24:19 UTC

[pulsar-dotpulsar] branch master updated: Make ready for release 2.7.0

This is an automated email from the ASF dual-hosted git repository.

blankensteiner pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar-dotpulsar.git


The following commit(s) were added to refs/heads/master by this push:
     new bbd4bf0  Make ready for release 2.7.0
bbd4bf0 is described below

commit bbd4bf087768b8e9d2065b92caa76086ae176036
Author: Daniel Blankensteiner <db...@vmail.dk>
AuthorDate: Thu Dec 8 14:24:10 2022 +0100

    Make ready for release 2.7.0
---
 CHANGELOG.md                                |  6 ++++
 src/DotPulsar/DotPulsar.csproj              |  2 +-
 src/DotPulsar/Extensions/StateExtensions.cs | 49 +++++++++++++++++++++++------
 3 files changed, 47 insertions(+), 10 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index cfda092..d9f44d8 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
 
 The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
 
+## [2.7.0] - 2022-12-08
+
+### Added
+
+- DelayedStateMonitor for IState where onStateLeft returns a fault context that is passed to onStateReached
+
 ## [2.6.0] - 2022-12-06
 
 ### Added
diff --git a/src/DotPulsar/DotPulsar.csproj b/src/DotPulsar/DotPulsar.csproj
index bfb01b1..4b5853c 100644
--- a/src/DotPulsar/DotPulsar.csproj
+++ b/src/DotPulsar/DotPulsar.csproj
@@ -2,7 +2,7 @@
 
   <PropertyGroup>
     <TargetFrameworks>netstandard2.0;netstandard2.1;net6.0;net7.0</TargetFrameworks>
-    <Version>2.6.0</Version>
+    <Version>2.7.0</Version>
     <AssemblyVersion>$(Version)</AssemblyVersion>
     <FileVersion>$(Version)</FileVersion>
     <Authors>ApachePulsar,DanskeCommodities,dblank</Authors>
diff --git a/src/DotPulsar/Extensions/StateExtensions.cs b/src/DotPulsar/Extensions/StateExtensions.cs
index 90f0364..59eb54a 100644
--- a/src/DotPulsar/Extensions/StateExtensions.cs
+++ b/src/DotPulsar/Extensions/StateExtensions.cs
@@ -110,13 +110,13 @@ public static class StateExtensions
     /// <returns>
     /// ValueTask that will run as long as a final state is not entered.
     /// </returns>
-    public static async ValueTask DelayedStateMonitor<TEntity, TState>(
+    public static async ValueTask DelayedStateMonitor<TEntity, TState, TFaultContext>(
         this TEntity stateImplementer,
         TState state,
         TimeSpan delay,
-        Func<TEntity, TState, CancellationToken, ValueTask> onStateLeft,
-        Func<TEntity, TState, CancellationToken, ValueTask> onStateReached,
-        CancellationToken cancellationToken) where TEntity : IState<TState> where TState : notnull
+        Func<TEntity, TState, CancellationToken, ValueTask<TFaultContext>> onStateLeft,
+        Func<TEntity, TState, TFaultContext, CancellationToken, ValueTask> onStateReached,
+        CancellationToken cancellationToken) where TEntity : IState<TState> where TState : notnull where TFaultContext : class
     {
         while (true)
         {
@@ -126,9 +126,11 @@ public static class StateExtensions
             if (stateImplementer.IsFinalState(currentState))
                 return;
 
+            TFaultContext? faultContext = null;
+
             try
             {
-                await onStateLeft(stateImplementer, currentState, cancellationToken).ConfigureAwait(false);
+                faultContext = await onStateLeft(stateImplementer, currentState, cancellationToken).ConfigureAwait(false);
             }
             catch
             {
@@ -141,7 +143,8 @@ public static class StateExtensions
 
             try
             {
-                await onStateReached(stateImplementer, currentState, cancellationToken).ConfigureAwait(false);
+                if (faultContext is not null)
+                    await onStateReached(stateImplementer, currentState, faultContext, cancellationToken).ConfigureAwait(false);
             }
             catch
             {
@@ -150,6 +153,34 @@ public static class StateExtensions
         }
     }
 
+    /// <summary>
+    /// Will invoke the onStateLeft callback when the state if left (with delay) and onStateReached when it's reached again.
+    /// </summary>
+    /// <returns>
+    /// ValueTask that will run as long as a final state is not entered.
+    /// </returns>
+    public static async ValueTask DelayedStateMonitor<TEntity, TState>(
+        this TEntity stateImplementer,
+        TState state,
+        TimeSpan delay,
+        Func<TEntity, TState, CancellationToken, ValueTask> onStateLeft,
+        Func<TEntity, TState, CancellationToken, ValueTask> onStateReached,
+        CancellationToken cancellationToken) where TEntity : IState<TState> where TState : notnull
+    {
+        async ValueTask<string> onStateLeftFunction(TEntity entity, TState state, CancellationToken cancellationToken)
+        {
+            await onStateLeft(entity, state, cancellationToken).ConfigureAwait(false);
+            return string.Empty;
+        }
+
+        async ValueTask onStateReachedFunction(TEntity entity, TState state, string faultContext, CancellationToken cancellationToken)
+        {
+            await onStateReached(entity, state, cancellationToken).ConfigureAwait(false);
+        }
+
+        await stateImplementer.DelayedStateMonitor(state, delay, onStateLeftFunction, onStateReachedFunction, cancellationToken).ConfigureAwait(false);
+    }
+
     /// <summary>
     /// Will invoke the onStateLeft callback when the state if left (with delay) and onStateReached when it's reached again.
     /// </summary>
@@ -164,13 +195,13 @@ public static class StateExtensions
         Action<TEntity, TState> onStateReached,
         CancellationToken cancellationToken) where TEntity : IState<TState> where TState : notnull
     {
-        ValueTask onStateLeftFunction(TEntity entity, TState state, CancellationToken cancellationToken)
+        ValueTask<string> onStateLeftFunction(TEntity entity, TState state, CancellationToken cancellationToken)
         {
             onStateLeft(entity, state);
-            return new ValueTask();
+            return new ValueTask<string>(string.Empty);
         }
 
-        ValueTask onStateReachedFunction(TEntity entity, TState state, CancellationToken cancellationToken)
+        ValueTask onStateReachedFunction(TEntity entity, TState state, string faultContext, CancellationToken cancellationToken)
         {
             onStateReached(entity, state);
             return new ValueTask();