// Copyright (c) Microsoft. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. // =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+ // // DataflowLinkOptions.cs // // // DataflowLinkOptions type for configuring links between dataflow blocks // // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- using System; using System.Diagnostics; using System.Threading.Tasks; namespace System.Threading.Tasks.Dataflow { /// /// Provides options used to configure a link between dataflow blocks. /// /// /// is mutable and can be configured through its properties. /// When specific configuration options are not set, the following defaults are used: /// /// /// Options /// Default /// /// /// PropagateCompletion /// False /// /// /// MaxMessages /// DataflowBlockOptions.Unbounded (-1) /// /// /// Append /// True /// /// /// Dataflow blocks capture the state of the options at linking. Subsequent changes to the provided /// instance should not affect the behavior of a link. /// [DebuggerDisplay("PropagateCompletion = {PropagateCompletion}, MaxMessages = {MaxMessages}, Append = {Append}")] public class DataflowLinkOptions { /// /// A constant used to specify an unlimited quantity for members /// that provide an upper bound. This field is a constant tied to . /// internal const Int32 Unbounded = DataflowBlockOptions.Unbounded; /// Whether the linked target will have completion and faulting notification propagated to it automatically. private Boolean _propagateCompletion = false; /// The maximum number of messages that may be consumed across the link. private Int32 _maxNumberOfMessages = Unbounded; /// Whether the link should be appended to the source’s list of links, or whether it should be prepended. private Boolean _append = true; /// A default instance of . /// /// Do not change the values of this instance. It is shared by all of our blocks when no options are provided by the user. /// internal static readonly DataflowLinkOptions Default = new DataflowLinkOptions(); /// A cached instance of . /// /// 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. /// internal static readonly DataflowLinkOptions UnlinkAfterOneAndPropagateCompletion = new DataflowLinkOptions() { MaxMessages = 1, PropagateCompletion = true }; /// Initializes the . public DataflowLinkOptions() { } /// Gets or sets whether the linked target will have completion and faulting notification propagated to it automatically. public Boolean PropagateCompletion { get { return _propagateCompletion; } set { Debug.Assert(this != Default && this != UnlinkAfterOneAndPropagateCompletion, "Default and UnlinkAfterOneAndPropagateCompletion instances are supposed to be immutable."); _propagateCompletion = value; } } /// Gets or sets the maximum number of messages that may be consumed across the link. public Int32 MaxMessages { get { return _maxNumberOfMessages; } set { Debug.Assert(this != Default && this != UnlinkAfterOneAndPropagateCompletion, "Default and UnlinkAfterOneAndPropagateCompletion instances are supposed to be immutable."); if (value < 1 && value != Unbounded) throw new ArgumentOutOfRangeException("value"); _maxNumberOfMessages = value; } } /// Gets or sets whether the link should be appended to the source’s list of links, or whether it should be prepended. public Boolean Append { get { return _append; } set { Debug.Assert(this != Default && this != UnlinkAfterOneAndPropagateCompletion, "Default and UnlinkAfterOneAndPropagateCompletion instances are supposed to be immutable."); _append = value; } } } }