Example #1
0
        /// <summary>
        /// Registers a desire to read from the channel
        /// </summary>
        /// <param name="offer">A callback method for offering an item, use null to unconditionally accept</param>
        /// <param name="timeout">The time to wait for the operation, use zero to return a timeout immediately if no items can be read. Use a
        /// negative span to wait forever.</param>
        /// <returns>The async.</returns>
        public async Task <T> ReadAsync(TimeSpan timeout, ITwoPhaseOffer offer = null)
        {
            var tcs = new TaskCompletionSource <T>();
            await NetworkConfig.TransmitRequestAsync(new PendingNetworkRequest(this, typeof(T), timeout == Timeout.Infinite ? new DateTime(0) : DateTime.Now + timeout, offer, tcs));

            return(await tcs.Task);
        }
Example #2
0
        /// <summary>
        /// Registers a desire to write to the channel
        /// </summary>
        /// <param name="offer">A callback method for offering an item, use null to unconditionally accept</param>
        /// <param name="value">The value to write to the channel.</param>
        /// <param name="timeout">The time to wait for the operation, use zero to return a timeout immediately if no items can be read. Use a
        /// negative span to wait forever.</param>
        /// <returns>The async.</returns>
        public async Task WriteAsync(T value, TimeSpan timeout, ITwoPhaseOffer offer)
        {
            var tcs = new TaskCompletionSource <bool>();
            await NetworkConfig.TransmitRequestAsync(new PendingNetworkRequest(this, typeof(T), timeout == Timeout.Infinite ? new DateTime(0) : DateTime.Now + timeout, offer, tcs, value));

            await tcs.Task;
        }
Example #3
0
        /// <summary>
        /// Registers a desire to read from the channel
        /// </summary>
        /// <param name="offer">A callback method for offering an item, use null to unconditionally accept</param>
        public async Task <T> ReadAsync(ITwoPhaseOffer offer)
        {
            var tcs = new TaskCompletionSource <T>();
            await NetworkConfig.TransmitRequestAsync(new PendingNetworkRequest(this, typeof(T), Timeout.InfiniteDateTime, offer, tcs)).ConfigureAwait(false);

            return(await tcs.Task.ConfigureAwait(false));
        }
Example #4
0
        /// <summary>
        /// Registers a desire to write to the channel
        /// </summary>
        /// <param name="offer">A two-phase offer, use null to unconditionally accept</param>
        /// <param name="value">The value to write to the channel.</param>
        /// <returns>The async.</returns>
        public async Task WriteAsync(T value, ITwoPhaseOffer offer)
        {
            var tcs = new TaskCompletionSource <bool>();
            await NetworkConfig.TransmitRequestAsync(new PendingNetworkRequest(this, typeof(T), Timeout.InfiniteDateTime, offer, tcs, value)).ConfigureAwait(false);

            await tcs.Task.ConfigureAwait(false);
        }
Example #5
0
        /// <summary>
        /// Creates a channel that is wrapped in a profiling channel instance
        /// </summary>
        /// <returns>The profiling-wrapped channel.</returns>
        /// <param name="attribute">The channel attribute.</param>
        /// <typeparam name="T">The channel type parameter.</typeparam>
        private static IChannel <T> CreateNetworkChannel <T>(ChannelNameAttribute attribute)
        {
            // We do not support annoymous channels, so we assign a random ID
            if (string.IsNullOrWhiteSpace(attribute.Name))
            {
                attribute.Name = Guid.NewGuid().ToString("N");
            }

            // Transmit the desired channel properties to the channel server
            NetworkConfig.TransmitRequestAsync(new PendingNetworkRequest(attribute.Name, typeof(T), NetworkMessageType.CreateChannelRequest, attribute));
            return(new NetworkChannel <T>(attribute));
        }