小编Sor*_*aei的帖子

获取在WinRT中实现给定接口的所有类

我正在尝试获取在Windows 8商店应用程序中实现某个界面的类列表,但似乎WinRT中的反射非常不同,到目前为止我找不到这样做的好例子.

有谁知道,如何加载当前的程序集并循环它?

任何帮助深表感谢 :)

c# reflection windows-8 windows-runtime windows-store-apps

9
推荐指数
1
解决办法
1294
查看次数

如何测试演员不会在Akka中终止

我试图测试演员是否被终止,我知道有一种方法可以测试它是否被终止使用TestProbe expectTerminated

http://doc.akka.io/docs/akka/2.4.16/scala/testing.html#Watching_Other_Actors_from_Probes

但有没有办法测试相反的情况?

谢谢 :)

更新

在我的场景中,我有一个用户actor,它有一个或多个子actor,当它的所有子节点都断开连接(终止)时它将自行终止.

行为工作正常但我的问题是我只能测试没有孩子的场景并终止自己.我无法找到正确的断言来检查它是否仍然有孩子离开时没有终止.

这是一个简化的测试版本:

"Terminates itself if there are no connected clients" in {
  val userActor = system.ActorOf(UserActor.props())

  userActor ! UserActor.ClientDisconnected()

  val deathWatch = TestProbe()
  deathWatch.watch(userActor)
  deathWatch.expectTerminated(userActor, timeoutDuration)
}

"Not Terminates itself when there are still other clients connected" in {
  val userActor = system.ActorOf(UserActor.props())

  // Connecting a client
  userActor ! UserActor.ClientConnected(sessionId, accessToken)

  userActor ! UserActor.ClientDisconnected()

  // How can I test that userActor is not terminated?
}
Run Code Online (Sandbox Code Playgroud)

akka

5
推荐指数
1
解决办法
381
查看次数

Scala递归API调用可获取所有结果

我对Scala还是很陌生,我想实现的目标是对具有不同偏移量的API进行足够的调用,直到获得所有结果为止。

这是我所拥有的简化版本,我想知道是否还有一种更惯用的Scala方法。(代码示例可能不是100%准确,这只是我作为示例提出的内容)

def getProducts(
                 limit: Int = 50,
                 offset: Int = 0,
                 otherProducts: Seq[Product] = Seq()): Future[Seq[Product]] = {

  val eventualResponse: Future[ApiResponse] = apiService.getProducts(limit, offset)

  val results: Future[Seq[Product]] = eventualResponse.flatMap { response =>

    if (response.isComplete) {
      logger.info("Got every product!")
      Future.successful(response.products ++ otherProducts)
    } else {
      logger.info("Need to fetch more data...")

      val newOffset = offset + limit
      getProducts(limit, newOffset, otherProducts ++ response.products)
    }
  }

  results
}
Run Code Online (Sandbox Code Playgroud)

传递otherProducts参数只是感觉不正确:P

在此先感谢您的任何建议 :)

recursion functional-programming scala

4
推荐指数
1
解决办法
112
查看次数