-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathSophonDownloadSpeedLimiter.cs
More file actions
33 lines (26 loc) · 1.04 KB
/
SophonDownloadSpeedLimiter.cs
File metadata and controls
33 lines (26 loc) · 1.04 KB
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
using System;
using System.Threading;
using System.Threading.Tasks;
// ReSharper disable UnusedType.Global
// ReSharper disable InvalidXmlDocComment
// ReSharper disable IdentifierTypo
#nullable enable
namespace Hi3Helper.Sophon;
public class SophonDownloadSpeedLimiter
{
public static Func<nint, long, CancellationToken, ValueTask>? AddBytesOrWaitAsyncDelegate;
public nint Context { get; }
private SophonDownloadSpeedLimiter(nint serviceContext)
{
Context = serviceContext;
}
/// <summary>
/// Create an instance by using current service context.
/// </summary>
/// <param name="serviceContext">The context to be used for the service.</param>
/// <returns>An instance of the speed limiter</returns>
public static SophonDownloadSpeedLimiter CreateInstance(nint serviceContext)
=> new(serviceContext);
internal ValueTask AddBytesOrWaitAsync(long readBytes, CancellationToken token)
=> AddBytesOrWaitAsyncDelegate?.Invoke(Context, readBytes, token) ?? ValueTask.CompletedTask;
}