Skip to content

Commit

Permalink
Merge pull request #42 from yyjdelete/issue_35
Browse files Browse the repository at this point in the history
Only create VoidChannelPromise.Task when needed
  • Loading branch information
cuteant authored May 17, 2021
2 parents d9e9ce3 + 706a80b commit f6a6b2b
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/DotNetty.Transport/Channels/VoidChannelPromise.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ namespace DotNetty.Transport.Channels
using System.Threading.Tasks;
using DotNetty.Common.Utilities;
using DotNetty.Common.Concurrency;
using System.Threading;

public sealed class VoidChannelPromise : IPromise
{
Expand All @@ -35,6 +36,7 @@ public sealed class VoidChannelPromise : IPromise
private readonly IChannel _channel;
// Will be null if we should not propagate exceptions through the pipeline on failure case.
private readonly bool _fireException;
private readonly Lazy<Task> _task;

static VoidChannelPromise()
{
Expand All @@ -51,10 +53,10 @@ public VoidChannelPromise(IChannel channel, bool fireException)
if (channel is null) { ThrowHelper.ThrowArgumentNullException(ExceptionArgument.channel); }
_channel = channel;
_fireException = fireException;
Task = TaskUtil.FromException(Error);
_task = new Lazy<Task>(() => TaskUtil.FromException(Error), LazyThreadSafetyMode.ExecutionAndPublication);
}

public Task Task { get; }
public Task Task => _task.Value;

public bool IsVoid => true;

Expand Down

0 comments on commit f6a6b2b

Please sign in to comment.