diff --git a/CHANGES.md b/CHANGES.md index 327f66da40..3aa7562a11 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -16,7 +16,9 @@ To be released. disposed to clean up its internal resources. [[#485]] - `IStore.IterateStateReferences()` method became to receive `highestIndex`, `lowestIndex`, and `limit` parameters. [[#447], [#545]] - - Reworked `BlockChain.GetStates()` into `GetState()` which takes only one `Address` instead of `IEnumerable
`. [[#510], [#563]] + - Reworked `BlockChain.GetStates()` into `GetState()` which takes only one + `Address` instead of `IEnumerable
`. [[#510], [#563]] + - Removed the `linger` parameter from the `Swarm` constructor and added `waitFor` to `Swarm.StopAsync()`. [TBD] ### Added interfaces diff --git a/Libplanet/Net/Swarm.cs b/Libplanet/Net/Swarm.cs index de7a832ece..2ecaf3fec4 100644 --- a/Libplanet/Net/Swarm.cs +++ b/Libplanet/Net/Swarm.cs @@ -53,7 +53,6 @@ public class Swarm : IDisposable private readonly AsyncLock _blockSyncMutex; private readonly string _host; private readonly IList _iceServers; - private readonly TimeSpan _linger; private readonly ILogger _logger; @@ -87,7 +86,6 @@ public Swarm( PrivateKey privateKey, int appProtocolVersion, int millisecondsDialTimeout = 15000, - int millisecondsLinger = 1000, string host = null, int? listenPort = null, DateTimeOffset? createdAt = null, @@ -99,7 +97,6 @@ public Swarm( privateKey, appProtocolVersion, TimeSpan.FromMilliseconds(millisecondsDialTimeout), - TimeSpan.FromMilliseconds(millisecondsLinger), host, listenPort, createdAt, @@ -113,7 +110,6 @@ public Swarm( PrivateKey privateKey, int appProtocolVersion, TimeSpan dialTimeout, - TimeSpan linger, string host = null, int? listenPort = null, DateTimeOffset? createdAt = null, @@ -142,7 +138,6 @@ public Swarm( _host = host; _listenPort = listenPort; _appProtocolVersion = appProtocolVersion; - _linger = linger; if (_host != null && _listenPort is int listenPortAsInt) { @@ -286,7 +281,16 @@ public void Dispose() } public async Task StopAsync( - CancellationToken cancellationToken = default(CancellationToken)) + CancellationToken cancellationToken = default(CancellationToken) + ) + { + await StopAsync(TimeSpan.FromSeconds(1), cancellationToken); + } + + public async Task StopAsync( + TimeSpan waitFor, + CancellationToken cancellationToken = default(CancellationToken) + ) { _workerCancellationTokenSource?.Cancel(); _logger.Debug("Stopping..."); @@ -294,7 +298,7 @@ public async Task StopAsync( { if (Running) { - await Task.Delay(_linger, cancellationToken); + await Task.Delay(waitFor, cancellationToken); _broadcastQueue.ReceiveReady -= DoBroadcast; _replyQueue.ReceiveReady -= DoReply; @@ -2024,7 +2028,6 @@ private async Task ProcessRuntime( using (var dealer = new DealerSocket(ToNetMQAddress(req.Peer))) { - dealer.Options.Linger = _linger; _logger.Debug( "Trying to send {@Message} to {PeerAddress}...", req.Message,