-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathDownloadSpeedLimiter.cs
More file actions
30 lines (25 loc) · 1018 Bytes
/
DownloadSpeedLimiter.cs
File metadata and controls
30 lines (25 loc) · 1018 Bytes
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
using System;
using System.Threading;
using System.Threading.Tasks;
// ReSharper disable UnusedType.Global
namespace Hi3Helper.Http
{
public class DownloadSpeedLimiter
{
public static Func<nint, long, CancellationToken, ValueTask>? AddBytesOrWaitAsyncDelegate;
public nint Context { get; }
private DownloadSpeedLimiter(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 DownloadSpeedLimiter CreateInstance(nint serviceContext)
=> new(serviceContext);
internal ValueTask AddBytesOrWaitAsync(long readBytes, CancellationToken token)
=> AddBytesOrWaitAsyncDelegate?.Invoke(Context, readBytes, token) ?? ValueTask.CompletedTask;
}
}