-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
29 lines (27 loc) · 1012 Bytes
/
Copy pathProgram.cs
File metadata and controls
29 lines (27 loc) · 1012 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
// SPDX-License-Identifier: Apache-2.0
// samples/Resume: drop the transport, reconnect with the resume token, replay buffered events.
// Spec: §6.3.
using Arcp.Client;
using Arcp.Core.Messages;
using Arcp.Core.Transport;
using Arcp.Runtime;
var server = new ArcpServer(new ArcpServerOptions
{
Runtime = new RuntimeInfo { Name = "resume", Version = "1.0.0" },
});
server.RegisterAgent("counter", async (ctx, ct) =>
{
for (var i = 0; i < 5; i++) await ctx.LogAsync("info", $"tick {i}", ct);
return "done";
});
var (clientT, serverT) = MemoryTransport.Pair();
_ = server.AcceptAsync(serverT);
await using var client = await ArcpClient.ConnectAsync(clientT, new ArcpClientOptions
{
Client = new ClientInfo { Name = "resume-client", Version = "1.0.0" },
});
Console.WriteLine($"resume_token={client.ResumeToken}");
var handle = await client.SubmitAsync("counter");
await handle.Result;
Console.WriteLine("done — in production, the resume_token would be passed to a fresh connection");
return 0;