Skip to content
This repository has been archived by the owner on Dec 18, 2018. It is now read-only.

Add HubConnection.State #2204

Merged
merged 4 commits into from
May 14, 2018
Merged

Add HubConnection.State #2204

merged 4 commits into from
May 14, 2018

Conversation

JamesNK
Copy link
Member

@JamesNK JamesNK commented May 4, 2018

Fixes #2127

// TODO: Documentation
public enum HubConnectionStatus
{
Started,
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, would connected make more sense here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Could do! I went with Started and Stopped because of StartAsync and StopAsync.

🚲 🏠 @davidfowl @anurse

Copy link
Contributor

Choose a reason for hiding this comment

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

I like Started and Stopped as well, given the method names.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmmm, the methods are Started and Stopped but they're on a class with connection in the name.

I think I prefer Disconnected and Connected.

get
{
// Local copy for thread-safety
var connectionState = _connectionState;
Copy link

Choose a reason for hiding this comment

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

Since ConnectionState is a class, wouldn't this still reference the original object?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes but the field can be set to null by another thread in-between checking it is not null and getting IsStopped.

Copy is the wrong word. A better comment would be "Local reference for thread-safety".

Copy link

Choose a reason for hiding this comment

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

Ah. Thanks for the clarification 🙂

Copy link
Contributor

Choose a reason for hiding this comment

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

?. will do this for you (source)

It's mostly just a clever trick though, so I don't really mind either way. Was mostly just curious if if would do the Right Thing.

Copy link
Member Author

Choose a reason for hiding this comment

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

I like taking a local variable for thread-safety issues because it gives a good opportunity to comment and make it obvious that it is a thing future readers of the code need to think about.

@JamesNK JamesNK changed the title [WIP] Add HubConnection.Status Add HubConnection.State May 10, 2018
@JamesNK
Copy link
Member Author

JamesNK commented May 10, 2018

🆙 📅

@JamesNK
Copy link
Member Author

JamesNK commented May 10, 2018

@dotnet-bot test Windows Release x64 Build please

@JamesNK
Copy link
Member Author

JamesNK commented May 11, 2018

Hey @davidfowl @anurse, is there any value in having a Connecting and Disconnecting state?

@analogrelay
Copy link
Contributor

@JamesNK Yeah, I guess that makes sense. Automatic Reconnect is also going to to throw a complexity in there (do we need a Reconncting state? or do we just transition back to Connecting)

@JamesNK
Copy link
Member Author

JamesNK commented May 11, 2018

@davidfowl said two is fine. It's an enum so no reason more can't be added as needed.

Copy link
Contributor

@mikaelm12 mikaelm12 left a comment

Choose a reason for hiding this comment

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

A couple of nits but looks good.
We can add another state for reconnecting when we get there.

@@ -215,6 +224,58 @@ Task<ConnectionContext> ConnectionFactory(TransferFormat format)
});
}

[Fact]
public async Task StatusIsNotStartedUntilStartAsyncIsFinished()
Copy link
Contributor

Choose a reason for hiding this comment

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

The title should be "StatusIsNotConnected..."

}

[Fact]
public async Task StatusIsStoppedInCloseEvent()
Copy link
Contributor

Choose a reason for hiding this comment

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

And here replace Stopped with Disconnected

@JamesNK JamesNK merged commit 7625bbc into dev May 14, 2018
@JamesNK JamesNK deleted the jamesnk/hubconnection-status branch May 16, 2018 20:33
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants