本文整理汇总了C#中Channel.get方法的典型用法代码示例。如果您正苦于以下问题:C# Channel.get方法的具体用法?C# Channel.get怎么用?C# Channel.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Channel
的用法示例。
在下文中一共展示了Channel.get方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: deliverMsgs
// deliverMsgs waits on the delivery channel shared with readLoop and processMsg.
// It is used to deliver messages to asynchronous subscribers.
internal void deliverMsgs(Channel<Msg> ch)
{
Msg m;
while (true)
{
lock (mu)
{
if (isClosed())
return;
}
m = ch.get(-1);
if (m == null)
{
// the channel has been closed, exit silently.
return;
}
// Note, this seems odd message having the sub process itself,
// but this is good for performance.
if (!m.sub.processMsg(m))
{
lock (mu)
{
removeSub(m.sub);
}
}
}
}
示例2: Flush
public void Flush(int timeout)
{
if (timeout <= 0)
{
throw new ArgumentOutOfRangeException(
"Timeout must be greater than 0",
"timeout");
}
Channel<bool> ch = new Channel<bool>(1);
lock (mu)
{
if (isClosed())
throw new NATSConnectionClosedException();
sendPing(ch);
}
try
{
bool rv = ch.get(timeout);
if (!rv)
{
lastEx = new NATSConnectionClosedException();
}
}
catch (NATSTimeoutException te)
{
lastEx = te;
}
catch (Exception e)
{
lastEx = new NATSException("Flush channel error.", e);
}
if (lastEx != null)
{
removeFlushEntry(ch);
throw lastEx;
}
}
示例3: Flush
public void Flush(int timeout)
{
if (timeout <= 0)
{
throw new ArgumentOutOfRangeException(
"Timeout must be greater than 0",
"timeout");
}
Channel<bool> ch = new Channel<bool>(1);
try
{
lock (mu)
{
if (isClosed())
throw new NATSConnectionClosedException();
sendPing(ch);
}
bool rv = ch.get(timeout);
if (!rv)
{
throw new NATSConnectionClosedException();
}
}
catch (Exception e)
{
removeFlushEntry(ch);
// Note, don't call saveFlushException in a finally clause
// because we don't know if the caller will handle the rethrown
// exception.
if (e is NATSTimeoutException || e is NATSConnectionClosedException)
{
saveFlushException(ch, e);
throw;
}
else
{
// wrap other system exceptions
var ex = new NATSException("Flush error.", e);
saveFlushException(ch, ex);
throw ex;
}
}
}