-
-
Notifications
You must be signed in to change notification settings - Fork 722
/
ISocketProtocol.cs
103 lines (93 loc) · 3.75 KB
/
ISocketProtocol.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
using System;
using System.Threading;
using System.Threading.Tasks;
using StrawberryShake.Transport.WebSockets.Messages;
namespace StrawberryShake.Transport.WebSockets;
/// <summary>
/// Delegate that is invoked whenever a message is received by the protocol
/// </summary>
/// <param name="operationId">The ide of the operation that the message belongs to</param>
/// <param name="message">The message</param>
/// <param name="cancellationToken">A token to cancel processing the message</param>
public delegate ValueTask OnReceiveAsync(
string operationId,
OperationMessage message,
CancellationToken cancellationToken);
/// <summary>
/// A protocol that can be used to communicate to a GraphQL server over
/// <see cref="ISocketClient"/>
/// </summary>
public interface ISocketProtocol : IAsyncDisposable
{
/// <summary>
/// A even that is called when the <see cref="ISocketProtocol"/> is disposed
/// </summary>
event EventHandler Disposed;
/// <summary>
/// Starts a new operation on the server
/// </summary>
/// <param name="operationId">
/// The id of the operation. This id must be unique!
/// </param>
/// <param name="request">
/// The <see cref="OperationRequest"/> that contains the definition of the operation
/// </param>
/// <param name="cancellationToken">
/// A <see cref="CancellationToken"/> to cancel the start of the operation
/// </param>
/// <returns>A task that is completed once the operation is started</returns>
Task StartOperationAsync(
string operationId,
OperationRequest request,
CancellationToken cancellationToken);
/// <summary>
/// Stops a operation on the server
/// </summary>
/// <param name="operationId">The id of the operation to stop</param>
/// <param name="cancellationToken">
/// A <see cref="CancellationToken"/> to cancel the stop of the operation
/// </param>
/// <returns>A task that is completed once the operation is stopped</returns>
Task StopOperationAsync(
string operationId,
CancellationToken cancellationToken);
/// <summary>
/// Initializes the protocol over a <see cref="ISocketClient"/> on the server.
/// </summary>
/// <param name="cancellationToken">
/// A <see cref="CancellationToken"/> to cancel the initialization
/// </param>
/// <returns>A task that is completed once the protocol is established</returns>
Task InitializeAsync(CancellationToken cancellationToken);
/// <summary>
/// Terminates the protocol and the communication with the server
/// </summary>
/// <param name="cancellationToken">
/// A <see cref="CancellationToken"/> to cancel the termination
/// </param>
/// <returns>A task that is completed once the protocol is terminated</returns>
Task TerminateAsync(CancellationToken cancellationToken);
/// <summary>
/// Subscribes a listener to receive all messages that the server sends over this protocol
/// </summary>
/// <param name="listener">
/// The listener that is invoked on every message
/// </param>
void Subscribe(OnReceiveAsync listener);
/// <summary>
/// Unsubscribes a listener from the protocol..
/// </summary>
/// <param name="listener"></param>
void Unsubscribe(OnReceiveAsync listener);
/// <summary>
/// Notify the protocol to complete
/// </summary>
/// <param name="operationId">The id of the operation to stop</param>
/// <param name="cancellationToken">
/// A <see cref="CancellationToken"/> to cancel the notification
/// </param>
/// <returns>A task that is completed once the notification is completed</returns>
ValueTask NotifyCompletion(
string operationId,
CancellationToken cancellationToken);
}