diff --git a/src/Proto.Actor/Context/ActorContext.cs b/src/Proto.Actor/Context/ActorContext.cs index 2744d677ea..50e0259762 100644 --- a/src/Proto.Actor/Context/ActorContext.cs +++ b/src/Proto.Actor/Context/ActorContext.cs @@ -231,6 +231,33 @@ public void ReenterAfter(Task target, Action action) ScheduleContinuation(target, cont); } + + public void ReenterAfter(Task target, Action action) + { + var msg = _messageOrEnvelope; + + var cont = new Continuation( + () => { + action(target); + return Task.CompletedTask; + }, + msg, + Actor); + + ScheduleContinuation(target, cont); + } + + public void ReenterAfter(Task target, Func action) + { + var msg = _messageOrEnvelope; + + var cont = new Continuation( + () => action(target), + msg, + Actor); + + ScheduleContinuation(target, cont); + } public Task Receive(MessageEnvelope envelope) { diff --git a/src/Proto.Actor/Context/ActorContextDecorator.cs b/src/Proto.Actor/Context/ActorContextDecorator.cs index 8931fed0c4..df03005229 100644 --- a/src/Proto.Actor/Context/ActorContextDecorator.cs +++ b/src/Proto.Actor/Context/ActorContextDecorator.cs @@ -72,6 +72,12 @@ public virtual void ReenterAfter(Task target, Func, Task> action) public virtual void ReenterAfter(Task target, Action action) => _context.ReenterAfter(target, action); + public void ReenterAfter(Task target, Action action) => + _context.ReenterAfter(target, action); + + public void ReenterAfter(Task target, Func action) => + _context.ReenterAfter(target, action); + public CapturedContext Capture() => _context.Capture(); public void Apply(CapturedContext capturedContext) => _context.Apply(capturedContext); diff --git a/src/Proto.Actor/Context/IContext.cs b/src/Proto.Actor/Context/IContext.cs index bae94b6825..a71bda00ab 100644 --- a/src/Proto.Actor/Context/IContext.cs +++ b/src/Proto.Actor/Context/IContext.cs @@ -90,6 +90,26 @@ public interface IContext : ISenderContext, IReceiverContext, ISpawnerContext, I /// the Task to await /// the continuation to call once the task is completed void ReenterAfter(Task target, Action action); + + /// + /// 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. + /// + /// the Task to await + /// the continuation to call once the task is completed + void ReenterAfter(Task target, Action action); + + /// + /// 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. + /// + /// the Task to await + /// the continuation to call once the task is completed + void ReenterAfter(Task target, Func action); /// /// Captures the current MessageOrEnvelope for the ActorContext