Skip to content

Commit

Permalink
Allow workflow delay to be performed in-process
Browse files Browse the repository at this point in the history
  • Loading branch information
stidsborg committed Jan 3, 2025
1 parent ee21fd0 commit 53d4cde
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Threading.Tasks;
using Cleipnir.ResilientFunctions.Domain;
using Cleipnir.ResilientFunctions.Domain.Exceptions.Commands;
using Cleipnir.ResilientFunctions.Helpers;
using Cleipnir.ResilientFunctions.Messaging;
using Cleipnir.ResilientFunctions.Storage;

Expand Down Expand Up @@ -39,12 +40,15 @@ public void Deconstruct(out Effect effect, out Messages messages, out States sta

public async Task RegisterCorrelation(string correlation) => await Correlations.Register(correlation);

public Task Delay(TimeSpan @for) => Delay(until: DateTime.UtcNow + @for);
public Task Delay(DateTime until)
public Task Delay(TimeSpan @for, bool suspend = true) => Delay(until: DateTime.UtcNow + @for, suspend);
public Task Delay(DateTime until, bool suspend = true)
{
if (until <= DateTime.UtcNow)
return Task.CompletedTask;

if (!suspend)
return Task.Delay((until - DateTime.UtcNow).RoundUpToZero());

throw new PostponeInvocationException(until);
}
}

0 comments on commit 53d4cde

Please sign in to comment.