Class ServerStream
The server's single stream of persistent changes: each write takes the next position, which sync tokens count.
Inherited Members
Namespace: Uniform.Matrix.Server.Sync
Assembly: Uniform.Matrix.Server.dll
Syntax
public sealed class ServerStream
Remarks
Writes run one at a time, so positions are committed in order and a sync from position n never misses a change at n + 1 that commits late.
Constructors
| Edit this page View SourceServerStream(IDbContextFactory<ServerDbContext>, IHostApplicationLifetime?)
Create the stream over the database's stored positions.
Declaration
public ServerStream(IDbContextFactory<ServerDbContext> contexts, IHostApplicationLifetime? lifetime = null)
Parameters
| Type | Name | Description |
|---|---|---|
| IDbContextFactory<ServerDbContext> | contexts | The database. |
| IHostApplicationLifetime | lifetime | The host, whose stopping ends the waits of long-polling clients; null for none. |
Properties
| Edit this page View SourceStopping
Cancelled when the server starts to stop: long-polling clients then get their answer at once, so that stopping need not wait for their timeouts.
Declaration
public CancellationToken Stopping { get; }
Property Value
| Type | Description |
|---|---|
| CancellationToken |
Methods
| Edit this page View SourceAdvanceAsync(CancellationToken)
Take a position for a change that is not stored, such as typing, so waiting syncs see it.
Declaration
public Task<long> AdvanceAsync(CancellationToken cancellationToken)
Parameters
| Type | Name | Description |
|---|---|---|
| CancellationToken | cancellationToken |
Returns
| Type | Description |
|---|---|
| Task<long> |
GetCurrentAsync(CancellationToken)
Return the latest committed position.
Declaration
public Task<long> GetCurrentAsync(CancellationToken cancellationToken)
Parameters
| Type | Name | Description |
|---|---|---|
| CancellationToken | cancellationToken |
Returns
| Type | Description |
|---|---|
| Task<long> |
WaitPastAsync(long, TimeSpan, CancellationToken, CancellationToken)
Wait until the stream moves past since, timeout passes or endEarly is cancelled; return the current position.
Declaration
public Task<long> WaitPastAsync(long since, TimeSpan timeout, CancellationToken cancellationToken, CancellationToken endEarly = default)
Parameters
| Type | Name | Description |
|---|---|---|
| long | since | Position the caller has. |
| TimeSpan | timeout | Longest wait. |
| CancellationToken | cancellationToken | Cancels the wait with an exception. |
| CancellationToken | endEarly | Ends the wait as the timeout does, without an exception, e.g. Stopping. |
Returns
| Type | Description |
|---|---|
| Task<long> |
WriteAsync<T>(Func<long, Task<T>>, CancellationToken)
Run write with the next position, alone; the position becomes current when it returns.
Declaration
public Task<T> WriteAsync<T>(Func<long, Task<T>> write, CancellationToken cancellationToken)
Parameters
| Type | Name | Description |
|---|---|---|
| Func<long, Task<T>> | write | |
| CancellationToken | cancellationToken |
Returns
| Type | Description |
|---|---|
| Task<T> |
Type Parameters
| Name | Description |
|---|---|
| T |
Remarks
Throwing leaves the position unused; the next write takes it again.