Skip to content

CompositeChangeToken.ActiveChangeCallbacks returns true when not all inner change tokens do so #40677

Open
@KalleOlaviNiemitalo

Description

@KalleOlaviNiemitalo

Description

CompositeChangeToken.ActiveChangeCallbacks returns true if at least one of the inner change tokens has active callbacks. It seems to me that it should return true only if all inner change tokens have active callbacks.

Rationale

IChangeToken.ActiveChangeCallbacks indicates whether the consumer can rely on its callback being invoked, or must instead poll the IChangeToken.HasChanged property.

  • If some of the inner change tokens of CompositeChangeToken have active callbacks but others don't, then the current implementation of CompositeChangeToken.ActiveChangeCallbacks returns true, and the consumer may rely on the callback. However, it would be safer to poll in this situation, as some of the inner change tokens may detect a change but not invoke the callback. That is, CompositeChangeToken.ActiveChangeCallbacks should return false.
  • If there are no inner change tokens, then CompositeChangeToken.ActiveChangeCallbacks returns false, directing the consumer to poll the IChangeToken.HasChanged property. However, HasChanged will constantly return false because no change can ever be detected. It might be more efficient not to poll in this situation. That is, CompositeChangeToken.ActiveChangeCallbacks should perhaps return true. I have not benchmarked this.

Configuration

Microsoft.Extensions.Primitives 2.1.6, but 5.0.0-preview.7.20364.11 behaves the same:

for (int i = 0; i < ChangeTokens.Count; i++)
{
if (ChangeTokens[i].ActiveChangeCallbacks)
{
ActiveChangeCallbacks = true;
break;
}
}

Regression?

No, it has always been like this.

Other information

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions