Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Square complexity in Signal when using AdviseOnce pattern #224

Open
nerzhulart opened this issue May 18, 2021 · 0 comments
Open

Square complexity in Signal when using AdviseOnce pattern #224

nerzhulart opened this issue May 18, 2021 · 0 comments
Assignees

Comments

@nerzhulart
Copy link
Contributor

If we call CurrentClientLifetime N times and then terminate lifetime of LocalCodeWithMeClientManager which removes a client we get a N^2 calls of ValueLifetime.ClearValueIfNotAlive

    public static Lifetime CurrentClientLifetime(this ICodeWithMeClientManager manager)
    {
      var clientId = ClientId.Current;
      var lifetimeDefinition = Lifetime.Define(Lifetime.Eternal, $"Lifetime of {clientId}");
      Log.Assert(manager.Clients.Contains(clientId), $"Client manager doesn't know about {clientId}");
      var lifetime = lifetimeDefinition.Lifetime;
      manager.Clients.Advise(lifetime, (addRemove, triggeredId) =>
      {
        if (addRemove == AddRemove.Remove && triggeredId == clientId)
        {
          lifetimeDefinition.Terminate();
        }
      });
      return lifetime;
    }
....
  public class LocalCodeWithMeClientManager : ICodeWithMeClientManager
  {
    public LocalCodeWithMeClientManager(Lifetime lifetime)
    {
      Clients.Add(ClientId.LocalId);
      lifetime.OnTermination(() => Clients.Remove(ClientId.LocalId));
    }

    public IViewableSet<ClientId> Clients { get; } = new ViewableSet<ClientId>();
  }

image
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants