-
Notifications
You must be signed in to change notification settings - Fork 1k
/
ActorRef.Extensions.cs
42 lines (38 loc) · 1.96 KB
/
ActorRef.Extensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//-----------------------------------------------------------------------
// <copyright file="ActorRef.Extensions.cs" company="Akka.NET Project">
// Copyright (C) 2009-2023 Lightbend Inc. <http://www.lightbend.com>
// Copyright (C) 2013-2023 .NET Foundation <https://github.com/akkadotnet/akka.net>
// </copyright>
//-----------------------------------------------------------------------
using System;
namespace Akka.Actor
{
/// <summary>
/// This class contains extension methods used for working with <see cref="IActorRef">ActorRefs</see>.
/// </summary>
public static class ActorRefExtensions
{
/// <summary>
/// Determines if the specified <paramref name="actorRef"/> is invalid.
/// An <paramref name="actorRef"/> is thought to be invalid if it's one of the following:
/// <see langword="null"/>, <see cref="Nobody"/>, and <see cref="DeadLetterActorRef"/>
/// </summary>
/// <param name="actorRef">The actor that is being tested.</param>
/// <returns><c>true</c> if the <paramref name="actorRef"/> is invalid; otherwise <c>false</c>.</returns>
public static bool IsNobody(this IActorRef actorRef)
{
return actorRef is null || actorRef is Nobody || actorRef is DeadLetterActorRef
|| actorRef.Path is null || (actorRef.Path.Uid == 0 && actorRef.Path.Name == "deadLetters");
}
/// <summary>
/// Returns the <paramref name="actorRef"/>'s value if it's not <see langword="null"/>, <see cref="Nobody"/>,
/// or <see cref="DeadLetterActorRef"/>. Otherwise return the result of evaluating `elseValue`.
/// </summary>
/// <param name="actorRef">The actor that is being tested.</param>
/// <param name="elseValue">TBD</param>
public static IActorRef GetOrElse(this IActorRef actorRef, Func<IActorRef> elseValue)
{
return actorRef.IsNobody() ? elseValue() : actorRef;
}
}
}