Rate Policy

This commit is contained in:
2026-07-13 17:15:00 +03:00
parent 31bda58460
commit 4f6d2d0801
46 changed files with 3142 additions and 468 deletions
+53
View File
@@ -0,0 +1,53 @@
using Esiur.Core;
using Esiur.Data.Types;
using Esiur.Resource;
namespace Esiur.Tests.Unit.Integration;
[Resource]
public partial class StreamResource
{
[Export]
public async IAsyncEnumerable<int> Numbers(int count, InvocationContext context)
{
for (var i = 0; i < count; i++)
{
await Task.Delay(5, context.CancellationToken);
yield return i;
}
}
[Export]
public async IAsyncEnumerable<int> Infinite(InvocationContext context)
{
var value = 0;
while (true)
{
await Task.Delay(5, context.CancellationToken);
yield return value++;
}
}
[Export]
[Stream(StreamMode.Push, Pausable = true)]
public AsyncReply<int> Pausable(InvocationContext context)
{
var reply = new AsyncReply<int>();
Task.Run(async () =>
{
await Task.Delay(100);
for (var i = 0; i < 3; i++)
{
await context.WaitWhileHaltedAsync();
reply.TriggerChunk(i);
await Task.Delay(100);
}
reply.Trigger(0);
});
return reply;
}
}