Skip to content

Conversation

@jviau
Copy link
Member

@jviau jviau commented Oct 16, 2023

This PR does the following:

  1. Adds another sample on how to implement the Counter entity.
  2. Adds bool HasState to TaskEntityState, so there is a quick way to know if an entity has any serialized state or not.
  3. Adds a T? defaultValue to .GetState<T> to make the new entity scenario easier (won't have any state).
  4. Reworks TaskEntityShim.StateShim a bit to be more robust with multiple state fetches, particularly when/if they change type.

{
return dispatcher.DispatchAsync(operation =>
{
if (operation.State.GetState(typeof(int)) is null)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shows how to do this before any of the new APIs. If we think this is good enough, can always revert the new API changes here.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using the new APIs would make more sense here I think.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes here are to make it a bit more robust when it is accessed multiple times with different types. Today the following would throw:

operation.State.GetState(typeof(object));
operation.State.GetState(typeof(int));

With this change, it will be possible.

Copy link
Member

@sebastianburckhardt sebastianburckhardt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some minor suggestions, otherwise looks good to me.

public abstract class TaskEntityState
{
/// <summary>
/// Gets a value indicating whether this entity has state or not yet.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Gets a value indicating whether this entity has state or not yet.
/// Gets a value indicating whether this entity has state or not yet / anymore.

public void Rollback()
{
this.CurrentState = this.checkpointValue;
this.cachedValue = null;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that clearing the cache explicitly seems like a good idea here.

(since the code may have modified the object without calling SetState and then the comparison in the setter does not catch that it was modified).

{
return dispatcher.DispatchAsync(operation =>
{
if (operation.State.GetState(typeof(int)) is null)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using the new APIs would make more sense here I think.

@jviau jviau merged commit e54807d into microsoft:feature/entities Oct 17, 2023
@jviau jviau deleted the entity-state branch October 17, 2023 22:37
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

Successfully merging this pull request may close these issues.

2 participants