1 // Copyright (c) Microsoft. All rights reserved.
2 // Licensed under the MIT license. See LICENSE file in the project root for full license information.
4 // =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
6 // DataflowLinkOptions.cs
9 // DataflowLinkOptions type for configuring links between dataflow blocks
11 // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
14 using System.Diagnostics;
15 using System.Threading.Tasks;
17 namespace System.Threading.Tasks.Dataflow
20 /// Provides options used to configure a link between dataflow blocks.
23 /// <see cref="DataflowLinkOptions"/> is mutable and can be configured through its properties.
24 /// When specific configuration options are not set, the following defaults are used:
25 /// <list type="table">
27 /// <term>Options</term>
28 /// <description>Default</description>
31 /// <term>PropagateCompletion</term>
32 /// <description>False</description>
35 /// <term>MaxMessages</term>
36 /// <description>DataflowBlockOptions.Unbounded (-1)</description>
39 /// <term>Append</term>
40 /// <description>True</description>
43 /// Dataflow blocks capture the state of the options at linking. Subsequent changes to the provided
44 /// <see cref="DataflowLinkOptions"/> instance should not affect the behavior of a link.
46 [DebuggerDisplay("PropagateCompletion = {PropagateCompletion}, MaxMessages = {MaxMessages}, Append = {Append}")]
47 public class DataflowLinkOptions
50 /// A constant used to specify an unlimited quantity for <see cref="DataflowLinkOptions"/> members
51 /// that provide an upper bound. This field is a constant tied to <see cref="DataflowLinkOptions.Unbounded"/>.
53 internal const Int32 Unbounded = DataflowBlockOptions.Unbounded;
55 /// <summary>Whether the linked target will have completion and faulting notification propagated to it automatically.</summary>
56 private Boolean _propagateCompletion = false;
57 /// <summary>The maximum number of messages that may be consumed across the link.</summary>
58 private Int32 _maxNumberOfMessages = Unbounded;
59 /// <summary>Whether the link should be appended to the source’s list of links, or whether it should be prepended.</summary>
60 private Boolean _append = true;
62 /// <summary>A default instance of <see cref="DataflowLinkOptions"/>.</summary>
64 /// Do not change the values of this instance. It is shared by all of our blocks when no options are provided by the user.
66 internal static readonly DataflowLinkOptions Default = new DataflowLinkOptions();
68 /// <summary>A cached instance of <see cref="DataflowLinkOptions"/>.</summary>
70 /// Do not change the values of this instance. It is shared by all of our blocks that need to unlink after one message has been consumed.
72 internal static readonly DataflowLinkOptions UnlinkAfterOneAndPropagateCompletion = new DataflowLinkOptions() { MaxMessages = 1, PropagateCompletion = true };
74 /// <summary>Initializes the <see cref="DataflowLinkOptions"/>.</summary>
75 public DataflowLinkOptions()
79 /// <summary>Gets or sets whether the linked target will have completion and faulting notification propagated to it automatically.</summary>
80 public Boolean PropagateCompletion
82 get { return _propagateCompletion; }
85 Debug.Assert(this != Default && this != UnlinkAfterOneAndPropagateCompletion, "Default and UnlinkAfterOneAndPropagateCompletion instances are supposed to be immutable.");
86 _propagateCompletion = value;
90 /// <summary>Gets or sets the maximum number of messages that may be consumed across the link.</summary>
91 public Int32 MaxMessages
93 get { return _maxNumberOfMessages; }
96 Debug.Assert(this != Default && this != UnlinkAfterOneAndPropagateCompletion, "Default and UnlinkAfterOneAndPropagateCompletion instances are supposed to be immutable.");
97 if (value < 1 && value != Unbounded) throw new ArgumentOutOfRangeException("value");
98 _maxNumberOfMessages = value;
102 /// <summary>Gets or sets whether the link should be appended to the source’s list of links, or whether it should be prepended.</summary>
103 public Boolean Append
105 get { return _append; }
108 Debug.Assert(this != Default && this != UnlinkAfterOneAndPropagateCompletion, "Default and UnlinkAfterOneAndPropagateCompletion instances are supposed to be immutable.");