Skip to content

Commit

Permalink
add reenterafter overloads (#1671)
Browse files Browse the repository at this point in the history
  • Loading branch information
rogeralsing authored Jun 15, 2022
1 parent 2fc538d commit 3a29bf5
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/Proto.Actor/Context/ActorContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,33 @@ public void ReenterAfter(Task target, Action action)

ScheduleContinuation(target, cont);
}

public void ReenterAfter(Task target, Action<Task> action)
{
var msg = _messageOrEnvelope;

var cont = new Continuation(
() => {
action(target);
return Task.CompletedTask;
},
msg,
Actor);

ScheduleContinuation(target, cont);
}

public void ReenterAfter(Task target, Func<Task,Task> action)
{
var msg = _messageOrEnvelope;

var cont = new Continuation(
() => action(target),
msg,
Actor);

ScheduleContinuation(target, cont);
}

public Task Receive(MessageEnvelope envelope)
{
Expand Down
6 changes: 6 additions & 0 deletions src/Proto.Actor/Context/ActorContextDecorator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ public virtual void ReenterAfter<T>(Task<T> target, Func<Task<T>, Task> action)
public virtual void ReenterAfter(Task target, Action action) =>
_context.ReenterAfter(target, action);

public void ReenterAfter(Task target, Action<Task> action) =>
_context.ReenterAfter(target, action);

public void ReenterAfter(Task target, Func<Task, Task> action) =>
_context.ReenterAfter(target, action);

public CapturedContext Capture() => _context.Capture();

public void Apply(CapturedContext capturedContext) => _context.Apply(capturedContext);
Expand Down
20 changes: 20 additions & 0 deletions src/Proto.Actor/Context/IContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,26 @@ public interface IContext : ISenderContext, IReceiverContext, ISpawnerContext, I
/// <param name="target">the Task to await</param>
/// <param name="action">the continuation to call once the task is completed</param>
void ReenterAfter(Task target, Action action);

/// <summary>
/// Awaits the given target task and once completed, the given action is then completed within the actors concurrency
/// constraint.
/// The concept is called Reentrancy, where an actor can continue to process messages while also awaiting that some
/// asynchronous operation completes.
/// </summary>
/// <param name="target">the Task to await</param>
/// <param name="action">the continuation to call once the task is completed</param>
void ReenterAfter(Task target, Action<Task> action);

/// <summary>
/// Awaits the given target task and once completed, the given action is then completed within the actors concurrency
/// constraint.
/// The concept is called Reentrancy, where an actor can continue to process messages while also awaiting that some
/// asynchronous operation completes.
/// </summary>
/// <param name="target">the Task to await</param>
/// <param name="action">the continuation to call once the task is completed</param>
void ReenterAfter(Task target, Func<Task,Task> action);

/// <summary>
/// Captures the current MessageOrEnvelope for the ActorContext
Expand Down

0 comments on commit 3a29bf5

Please sign in to comment.