我对Rx.NET有些新意.是否有可能捕获任何订阅者可能抛出的异常?采取以下措施......
handler.FooStream.Subscribe(
_ => throw new Exception("Bar"),
_ => { });
Run Code Online (Sandbox Code Playgroud)
目前,我正在以每个订阅为基础,使用以下实例.其实现只使用ManualResetEvent来唤醒等待的线程.
public interface IExceptionCatcher
{
Action<T> Exec<T>(Action<T> action);
}
Run Code Online (Sandbox Code Playgroud)
并像这样使用它......
handler.FooStream.Subscribe(
_exceptionCatcher.Exec<Foo>(_ => throw new Exception("Bar")), //It's disappointing that this generic type can't be inferred
_ => { });
Run Code Online (Sandbox Code Playgroud)
我觉得必须有更好的方法.Rx.NET中的所有错误处理功能是否专门用于处理可观察到的错误?
编辑:根据请求,我的实现是https://gist.github.com/1409829(接口和实现分为prod代码中的不同程序集).欢迎反馈.这可能看起来很愚蠢,但我正在使用城堡windsor来管理许多不同的Rx用户.此异常捕获器已在此容器中注册
windsorContainer.Register(Component.For<IExceptionCatcher>().Instance(catcher));
Run Code Online (Sandbox Code Playgroud)
然后就像这样使用observable
IObservable的实例:
var exceptionCatcher =
new ExceptionCatcher(e =>
{
Logger.FatalException(
"Exception caught, shutting down.", e);
// Deal with unmanaged resources here
}, false);
/*
* Normally the code below exists in some class managed …
Run Code Online (Sandbox Code Playgroud) c# asynchronous exception-handling subscription system.reactive
我scalacOptions
在编译时试图弄清楚SBT 如何设置/追加使用时遇到了一些麻烦Build.scala
.我团队中的某个人从Akka中复制了一些代码,Build.scala
结果是一堆弃用的警告和一个功能警告.
$ reload
[info] Loading global plugins from /Users/xxx/.sbt/0.13/plugins
[info] Loading project definition from /Users/xxx/yyy/zzz/project
[info] Compiling 1 Scala source to /Users/xxx/yyy/zzz/project/target/scala-2.10/sbt-0.13/classes...
[warn] there were 3 deprecation warning(s); re-run with -deprecation for details
[warn] there were 1 feature warning(s); re-run with -feature for details
[warn] two warnings found
Run Code Online (Sandbox Code Playgroud)
我尝试过的事情
scalacOptions ++= Seq("-unchecked", "-feature")
到build.sbt
.我希望在Build.scala
编译之前加载它.scalacOptions ++= Seq(...., "-unchecked", "-feature")
在Build.scala
试图设置scalacOptions
之前reload
,但它似乎被丢弃
$ …
Run Code Online (Sandbox Code Playgroud)当尝试简化为与Moq匹配的Setup/Verify匹配创建相当复杂的表达式树时,我遇到了一些奇怪的行为.
假设我在嘲笑下面定义的简单接口
public interface IService
{
int Send(int value);
}
Run Code Online (Sandbox Code Playgroud)
以下代码表示5个测试.每个测试一个mockSender.Setup(...)
.任何人都可以解释为什么标记为失败的测试失败了吗?
[Test]
public void TestInlineSetup()
{
const int expected = 5;
var mockSender = new Mock<IService>(MockBehavior.Loose);
//passes
mockSender.Setup(s => s.Send(It.IsAny<int>())).Returns(expected);
//fails
var sendMatch = It.IsAny<int>();
mockSender.Setup(s => s.Send(sendMatch)).Returns(expected);
//passes
mockSender.Setup(s => s.Send(SendMatchFromMethod())).Returns(expected);
//fails
var sendMatch = SendMatchFromMethod();
mockSender.Setup(s => s.Send(sendMatch)).Returns(expected);
//fails (this is somewhat contrived, but I have reasons for wanting to curry this)
mockSender.Setup(s => s.Send(SendMatchFromCurriedMethod()())).Returns(expected);
Assert.That(mockSender.Object.Send(expected), Is.EqualTo(expected));
}
public static int SendMatchFromMethod()
{
return It.IsAny<int>();
} …
Run Code Online (Sandbox Code Playgroud) Scala 2.8.1
我使用解析器/组合器实现了一个非常简单的外部DSL,用于QA编写验收测试.
最近我添加了循环遍历一组表达式的能力
sealed trait Expr
...
//insert other case classes extending 'Expr' here
...
case class Repetition(times: Int, expressions: List[Expr]) extends Expr
class TestFixtureParser(....) extends RegexParsers {
val repeatParser: Parser[Expr] = (l("repeat") ~> number) ~ (l("{") ~> expressions <~ l("}")) ^^ {
case (times: Int) ~ (exprs: List[Expr]) => {
Repetition(times, exprs)
}
}
private val expressions: Parser[List[Expr]] = (repeatParser |
/*insert other Parser[Expr]s '|' together here */ | verifyParser ).*
}
Run Code Online (Sandbox Code Playgroud)
在构建时,我会warning: non variable type-argument ... …