c# - How to clean groups from produced by GroupBy - Stack Overflow

I made following observable, that filters only changes for given ResourceId:var valueChangesObs = even

I made following observable, that filters only changes for given ResourceId:

var valueChangesObs = events
  .GroupBy(e => e.ResourceId)
  .SelectMany(e => e.DistinctUntilChanged(e => e.ResouceValue))

However, the there will be too many groups overtime and I need to clean them.

I have another observable, that emits value, when ResourceId becomes deprecated and can be removed.

How to remove specific groups produced by GroupBy over time to avoid memory leak?

I'm have something TakeUntil in mind:

var valueChangesObs = events
  .GroupBy(x => x.ResourceId)
  .TakeUntil(group => g)) 
  .SelectMany(group => group
        .DistinctUntilChanged(x => x.ResouceValue)
        .TakeUntil(x => resourceDeprecatedObservable.First(y => y.ResourceId = x.ResourceId))); 

I made following observable, that filters only changes for given ResourceId:

var valueChangesObs = events
  .GroupBy(e => e.ResourceId)
  .SelectMany(e => e.DistinctUntilChanged(e => e.ResouceValue))

However, the there will be too many groups overtime and I need to clean them.

I have another observable, that emits value, when ResourceId becomes deprecated and can be removed.

How to remove specific groups produced by GroupBy over time to avoid memory leak?

I'm have something TakeUntil in mind:

var valueChangesObs = events
  .GroupBy(x => x.ResourceId)
  .TakeUntil(group => g)) 
  .SelectMany(group => group
        .DistinctUntilChanged(x => x.ResouceValue)
        .TakeUntil(x => resourceDeprecatedObservable.First(y => y.ResourceId = x.ResourceId))); 
Share Improve this question edited Mar 12 at 9:30 Liero asked Mar 12 at 9:01 LieroLiero 27.5k41 gold badges179 silver badges337 bronze badges 3
  • 1 How to remove specific groups produces by GroupBy over time to avoid memory leak? - since you say specific groups, what is the specification? and why isn't a simple Where sufficient? e.g. events.Where(x => IsResourceIdGood(x.ResourceId)).GroupBy(x => x.ResourceId) – Rand Random Commented Mar 12 at 9:09
  • They will become deprecated later at some point in time, for example when ResourceDeprecated event is emited – Liero Commented Mar 12 at 9:29
  • In other words, the groups (group = resource) are valid when they are created, but becames invalid, when resourec becomes invalid (e.g. resource is deleted from database) so no further events for that resource makes sense – Liero Commented Mar 12 at 9:31
Add a comment  | 

1 Answer 1

Reset to default 0

Use the .GroupByUntil operator

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744763089a4592289.html

相关推荐

  • c# - How to clean groups from produced by GroupBy - Stack Overflow

    I made following observable, that filters only changes for given ResourceId:var valueChangesObs = even

    7小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信