public async Task RunAsync()
            {
                _logger.LogDebug("debug");
                _logger.LogInformation("debug");
                _logger.LogWarning("debug");

                // this is just an example - practically, connecting the client
                // would be managed elsewhere - and the class would expect to
                // receive a connected client - and, that 'elsewhere' would also
                // dispose the client, etc.
                await _client.StartAsync();

                await using var map = await _client.GetDictionaryAsync <string, int>("test-map");

                await map.SetAsync("key", 42);

                var value = await map.GetAsync("key");

                if (value != 42)
                {
                    throw new Exception("Error!");
                }

                Console.WriteLine("It worked.");

                // destroy the map
                await _client.DestroyAsync(map);
            }
            private static async Task RunAsync(IHazelcastClient client, CancellationToken cancellationToken)
            {
                // 'await using' ensure that both the client and the map will be disposed before the method returns
                await using var c   = client;
                await using var map = await client.GetDictionaryAsync <string, int>("test-map");

                // loop while not canceled
                while (!cancellationToken.IsCancellationRequested)
                {
                    // pretend to do some work
                    var i = await map.GetAsync("foo");

                    i += 1;
                    await map.SetAsync("foo", i);

                    Console.WriteLine(i);

                    try
                    {
                        await Task.Delay(1000, cancellationToken);
                    }
                    catch (OperationCanceledException)
                    {
                        // expected
                    }
                }

                await client.DestroyAsync(map);
            }
Пример #3
0
            public async Task RunAsync()
            {
                _logger.LogDebug("debug");
                _logger.LogInformation("debug");
                _logger.LogWarning("debug");

                await using var map = await _client.GetMapAsync <string, int>("test-map");

                await map.SetAsync("key", 42);

                var value = await map.GetAsync("key");

                if (value != 42)
                {
                    throw new Exception("Error!");
                }

                Console.WriteLine("It worked.");

                // destroy the map
                await _client.DestroyAsync(map);
            }