Skip to content

Commit

Permalink
[PORT] make FutureActorRef<T> unsealed (#6331)
Browse files Browse the repository at this point in the history
* make `FutureActorRef<T>` unsealed (#6322)

* make `FutureActorRef<T>` unsealed

* extend FutureActorRef<T> for telemetry

* added API approvals

* approved API changes
  • Loading branch information
Aaronontheweb committed Jan 5, 2023
1 parent 965e4c3 commit 0070079
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 7 deletions.
Expand Up @@ -888,11 +888,12 @@ namespace Akka.Actor
public Failures() { }
public System.Collections.Generic.List<Akka.Actor.Failure> Entries { get; }
}
public sealed class FutureActorRef<T> : Akka.Actor.MinimalActorRef
public class FutureActorRef<T> : Akka.Actor.MinimalActorRef
{
public FutureActorRef(System.Threading.Tasks.TaskCompletionSource<T> result, Akka.Actor.ActorPath path, Akka.Actor.IActorRefProvider provider) { }
public override Akka.Actor.ActorPath Path { get; }
public override Akka.Actor.IActorRefProvider Provider { get; }
public virtual void DeliverAsk(object message, Akka.Actor.ICanTell destination) { }
protected override void TellInternal(object message, Akka.Actor.IActorRef sender) { }
}
public class static Futures
Expand Down
Expand Up @@ -890,11 +890,12 @@ namespace Akka.Actor
public Failures() { }
public System.Collections.Generic.List<Akka.Actor.Failure> Entries { get; }
}
public sealed class FutureActorRef<T> : Akka.Actor.MinimalActorRef
public class FutureActorRef<T> : Akka.Actor.MinimalActorRef
{
public FutureActorRef(System.Threading.Tasks.TaskCompletionSource<T> result, Akka.Actor.ActorPath path, Akka.Actor.IActorRefProvider provider) { }
public override Akka.Actor.ActorPath Path { get; }
public override Akka.Actor.IActorRefProvider Provider { get; }
public virtual void DeliverAsk(object message, Akka.Actor.ICanTell destination) { }
protected override void TellInternal(object message, Akka.Actor.IActorRef sender) { }
}
public class static Futures
Expand Down
Expand Up @@ -888,11 +888,12 @@ namespace Akka.Actor
public Failures() { }
public System.Collections.Generic.List<Akka.Actor.Failure> Entries { get; }
}
public sealed class FutureActorRef<T> : Akka.Actor.MinimalActorRef
public class FutureActorRef<T> : Akka.Actor.MinimalActorRef
{
public FutureActorRef(System.Threading.Tasks.TaskCompletionSource<T> result, Akka.Actor.ActorPath path, Akka.Actor.IActorRefProvider provider) { }
public override Akka.Actor.ActorPath Path { get; }
public override Akka.Actor.IActorRefProvider Provider { get; }
public virtual void DeliverAsk(object message, Akka.Actor.ICanTell destination) { }
protected override void TellInternal(object message, Akka.Actor.IActorRef sender) { }
}
public class static Futures
Expand Down
Expand Up @@ -885,11 +885,12 @@ namespace Akka.Actor
public Failures() { }
public System.Collections.Generic.List<Akka.Actor.Failure> Entries { get; }
}
public sealed class FutureActorRef<T> : Akka.Actor.MinimalActorRef
public class FutureActorRef<T> : Akka.Actor.MinimalActorRef
{
public FutureActorRef(System.Threading.Tasks.TaskCompletionSource<T> result, Akka.Actor.ActorPath path, Akka.Actor.IActorRefProvider provider) { }
public override Akka.Actor.ActorPath Path { get; }
public override Akka.Actor.IActorRefProvider Provider { get; }
public virtual void DeliverAsk(object message, Akka.Actor.ICanTell destination) { }
protected override void TellInternal(object message, Akka.Actor.IActorRef sender) { }
}
public class static Futures
Expand Down
11 changes: 9 additions & 2 deletions src/core/Akka/Actor/ActorRef.cs
Expand Up @@ -69,7 +69,7 @@ public interface IRepointableRef : IActorRefScope
///
/// ActorRef implementation used for one-off tasks.
/// </summary>
public sealed class FutureActorRef<T> : MinimalActorRef
public class FutureActorRef<T> : MinimalActorRef
{
private readonly TaskCompletionSource<T> _result;
private readonly ActorPath _path;
Expand Down Expand Up @@ -122,9 +122,12 @@ protected override void TellInternal(object message, IActorRef sender)
handled = _result.TrySetException(f.Cause
?? new TaskCanceledException("Task cancelled by actor via Failure message."));
break;
#pragma warning disable CS0618
// for backwards compatibility
case Failure f:
handled = _result.TrySetException(f.Exception
?? new TaskCanceledException("Task cancelled by actor via Failure message."));
?? new TaskCanceledException("Task cancelled by actor via Failure message."));
#pragma warning restore CS0618
break;
default:
_ = _result.TrySetException(new ArgumentException(
Expand All @@ -136,6 +139,10 @@ protected override void TellInternal(object message, IActorRef sender)
if (!handled && !_result.Task.IsCanceled)
_provider.DeadLetters.Tell(message ?? default(T), this);
}

public virtual void DeliverAsk(object message, ICanTell destination){
destination.Tell(message, this);
}
}


Expand Down
2 changes: 1 addition & 1 deletion src/core/Akka/Actor/Futures.cs
Expand Up @@ -164,7 +164,7 @@ public static Task<T> Ask<T>(this ICanTell self, Func<IActorRef, object> message
//The future actor needs to be registered in the temp container
provider.RegisterTempActor(future, path);
var message = messageFactory(future);
self.Tell(message, future);
future.DeliverAsk(message, self);

return result.Task;
}
Expand Down

0 comments on commit 0070079

Please sign in to comment.