Esempio n. 1
0
        /// <summary>
        /// Connect this instance to the other end.
        /// </summary>
        public async Task ConnectAsync()
        {
            LOG.DebugFormat("{0} is connecting", SelfID);
            if (!m_socket.Connected)
            {
                throw new InvalidOperationException("Cannot use socket if not connected");
            }
            try
            {
                m_stream = m_socket.GetStream();
                await NegotiateConnection();
            }
            catch
            {
                try { m_stream.Dispose(); }
                catch { }
                finally { m_stream = null; }

                try { m_socket.Close(); }
                catch { }

                try { m_readRequests.Retire(); }
                catch { }

                try { m_writeRequests.Retire(); }
                catch { }

                throw;
            }

            ReaderProcess(m_socket, m_stream, m_readRequests.AsWriteOnly(), SelfID).FireAndForget();
            WriterProcess(m_socket, m_stream, m_writeRequests.AsReadOnly(), SelfID).FireAndForget();
        }
Esempio n. 2
0
 public static Task RunWriter <T>(IChannel <T> channel, IEnumerable <T> values)
 {
     return(AutomationExtensions.RunTask(
                new { chan = channel.AsWriteOnly() },
                async self =>
     {
         foreach (var v in values)
         {
             await self.chan.WriteAsync(v);
         }
     }
                ));
 }