JetBrains / JetBrains/rd

Union of lifetime

Open
#498 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
417
Forks
62
Avg merge
9h 15m
Merged PRs (30d)
7

Description

## 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.
```c#
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
```c#
public interface IGpsLocation
{
public IObservable TrackLocation(Lifetime lifetime);
}
```

## Proposed API
In order to provide a way to dispose that definition need to create spicific definition
```c#
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
```c#
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
```c#
var lf = Lifetime.Intersection(globalLifetime, localLifetime1, localLifetime2);
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.