/
ISyncWorker.cs
49 lines (47 loc) · 2.18 KB
/
ISyncWorker.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
using System;
using System.Threading.Tasks;
using Orleans.SyncWork.Enums;
namespace Orleans.SyncWork;
/// <summary>
/// Provides a means of Starting long running work, polling said work, and retrieving an eventual result/exception.
/// </summary>
/// <typeparam name="TRequest">The type of request to dispatch.</typeparam>
/// <typeparam name="TResult">The type of result to receive.</typeparam>
public interface ISyncWorker<in TRequest, TResult> : IGrain
{
/// <summary>
/// Start long running work with the provided parameter.
/// </summary>
/// <param name="request">The parameter containing all necessary information to start the workload.</param>
/// <returns>true if work is started, false if it was already started.</returns>
Task<bool> Start(TRequest request);
/// <summary>
/// <para>
/// Start long running work with the provided parameter.
/// </para>
/// <para>
/// Supports cancellation, but any cancellation logic is up to the grain implementation. It could
/// conceivably return a result at the point of cancellation, or throw, depending on what makes sense for
/// the particular grain.
/// </para>
/// </summary>
/// <param name="request">The parameter containing all necessary information to start the workload.</param>
/// <param name="grainCancellationToken">The token for cancelling tasks.</param>
/// <returns>true if work is started, false if it was already started.</returns>
Task<bool> Start(TRequest request, GrainCancellationToken grainCancellationToken);
/// <summary>
/// Gets the long running work status.
/// </summary>
/// <returns>The status of the long running work.</returns>
Task<SyncWorkStatus> GetWorkStatus();
/// <summary>
/// The result of the long running work.
/// </summary>
/// <returns>The result of the work done through the SyncWorker.</returns>
Task<TResult?> GetResult();
/// <summary>
/// Gets the exception information when the long running work faulted.
/// </summary>
/// <returns>The exception information as it relates to the failure.</returns>
Task<Exception?> GetException();
}