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

Union of lifetime #498

Open
dmitry-bym opened this issue Oct 12, 2024 · 0 comments
Open

Union of lifetime #498

dmitry-bym opened this issue Oct 12, 2024 · 0 comments

Comments

@dmitry-bym
Copy link

dmitry-bym commented Oct 12, 2024

Background and Motivation

Again lifetimes is awesome so i integrated that everywhere and i have activatable view models. Basicaly its same aproach but to force deactivate view. And I came across that in some places I would like to use same view model so i want deactivate that only when no one use this.

public interface IActivatableViewModel
{
    public void Activate(Lifetime lifetime);
}

2nd example
I have gpsService which track location and i want to stop tracking only when no one use this

public interface IGpsLocation
{
    public IObservable<Location> TrackLocation(Lifetime lifetime);
}

Proposed API

In order to provide a way to dispose that definition need to create spicific definition

public class UnionLifetimeDefinition(Lifetime parentLifetime)
{
    public Lifetime Lifetime { get; }
    public void Add(Lifetemi lifetime);
}

Alternative Designs

I thought about same approach like with Intersection, but its not good due to the fact that will not have a way to terminate that. Smth like add method Union and DefineUnion to lifetime. Basicaly same stracture as with Intersection

    public Lifetime Union(Lifetime other) => Union(this, other);

    public static Lifetime Union(params Lifetime[] lifetimes);

    public static LifetimeDefinition DefineUnion(params Lifetime[] lifetimes);

but it not possible to terminate same way, for intersection its possible to use global lifetime in the same place

var lf = Lifetime.Intersection(globalLifetime, localLifetime1, localLifetime2);
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

1 participant