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

Add CancellationToken representing the lifetime of the IConnection #858

@davidfowl

Description

@davidfowl

Today since we only have an event for Disconnect, it makes it hard to write linear code that does something until the client disconnects. It should be possible to write a reconnect loop like this:

while (true)
{
    // Create a new connection    
    var connection = new HubConnectionBuilder()
                    .WithUrl("http://localhost:5000/cache")
                    .WithMessagePackProtocol()
                    .WithConsoleLogger()
                    .WithTransportType(TransportType.WebSockets)
                    .Build();

    // Start it
    await connection.StartAsync(); 
   
    // Do things while the connection is alive and wait for it to finish

    await connection.Lifetime.AsTask();

    // Dispose when it's done
    await connection.DisposeAsync();
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions