Skip to content

Commit b8a4d98

Browse files
committed
docs: update readme
1 parent ff8eb2e commit b8a4d98

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

README.md

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,34 @@
11
# McQuery.Net
2+
23
Library for .Net which implements Minecraft Query protocol. You can use it for getting statuses of a Minecraft server.
34

45
# Example of using
56

67
```cs
7-
static async Task DoSomething(IEnumerable<IPEndPoint> mcServersEndPoints)
8-
{
9-
McQueryService service = new(5, 5000, 500, 1000);
8+
IMcQueryClientFactory factory = new McQueryClientFactory();
9+
using var client = factory.Get();
1010

11-
List<Server> servers = mcServersEndPoints.Select(service.RegistrateServer).ToList();
11+
async Task ExecuteQueries(IReadOnlyCollection<IPEndPoint> endpoints, CancellationToken cancellationToken = default)
12+
{
13+
var queryTasks = endpoints.SelectMany<IPEndPoint, Task, Task>(
14+
endpoint =>
15+
[
16+
GetBasicStatusAndPrint(endpoint, cancellationToken),
17+
GetFullStatusAndPrint(endpoint, cancellationToken)
18+
],
19+
(_, task) => task
20+
).ToArray();
1221

13-
List<Task<IResponse>> requests = new();
14-
foreach (Server server in servers)
15-
{
16-
requests.Add(service.GetBasicStatusCommon(server));
17-
requests.Add(service.GetFullStatusCommon(server));
18-
}
22+
await Task.WhenAll(queryTasks);
23+
}
1924

20-
Task.WaitAll(requests.ToArray());
25+
async Task GetBasicStatusAndPrint(IPEndPoint endpoint, CancellationToken cancellationToken = default)
26+
{
27+
Console.WriteLine(await client.GetBasicStatusAsync(endpoint, cancellationToken));
28+
}
2129

22-
foreach (Task<IResponse> request in requests)
23-
{
24-
IResponse response = await request;
25-
Console.WriteLine(response.ToString() + "\n");
26-
}
30+
async Task GetFullStatusAndPrint(IPEndPoint endpoint, CancellationToken cancellationToken = default)
31+
{
32+
Console.WriteLine(await client.GetFullStatusAsync(endpoint, cancellationToken));
2733
}
2834
```

0 commit comments

Comments
 (0)