本文整理汇总了Scala中scala.concurrent.duration.DurationInt类的典型用法代码示例。如果您正苦于以下问题:Scala DurationInt类的具体用法?Scala DurationInt怎么用?Scala DurationInt使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DurationInt类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: UserTokenDaoSpec
//设置package包名称以及导入依赖的类
package daos
import scala.concurrent.Await
import play.api.libs.concurrent.Execution.Implicits.defaultContext
import play.api.test._
import play.api.test.Helpers._
import org.joda.time.DateTime
import org.specs2.mutable.Specification
import java.util.UUID
import scala.concurrent.Await
import scala.concurrent.duration.DurationInt
import models.UserToken
class UserTokenDaoSpec extends Specification {
val timeout = DurationInt(10).seconds
def fakeApp = FakeApplication(additionalConfiguration = Map("mongodb.uri" -> "mongodb://localhost:27017/test"))
def withUserTokenDao[T](t:UserTokenDao => T):T = running(fakeApp) {
val userTokenDao = new MongoUserTokenDao
Await.ready(userTokenDao.tokens.drop(), timeout)
t(userTokenDao)
}
val token = UserToken(id=UUID.randomUUID(), userId=UUID.randomUUID(), "[email protected]", new DateTime(), true)
"UserTokenDao" should {
"Persist and find a token" in withUserTokenDao { userTokenDao =>
val future = for {
_ <- userTokenDao.save(token)
maybeToken <- userTokenDao.find(token.id)
} yield maybeToken.map(_ == token)
Await.result(future, timeout) must beSome(true)
}
"Remove a token" in withUserTokenDao { userTokenDao =>
val future = for {
_ <- userTokenDao.save(token)
_ <- userTokenDao.remove(token.id)
maybeToken <- userTokenDao.find(token.id)
} yield maybeToken
Await.result(future, timeout) must beNone
}
}
}
示例2: ParentActor
//设置package包名称以及导入依赖的类
package com.github.uryyyyyyy.akka.helloworld.faultTolerance
import java.io.IOException
import akka.actor.SupervisorStrategy.{Escalate, Resume}
import akka.actor.{Actor, OneForOneStrategy, Props}
import scala.concurrent.duration.DurationInt
class ParentActor extends Actor {
override val supervisorStrategy =OneForOneStrategy(maxNrOfRetries = 10, withinTimeRange = new DurationInt(1).second ) {
case _: IOException => Resume
case _: Exception => Escalate
}
def receive = {
case x => {
val actor1 = context.actorOf(Props[ChildActor1])
val actor2 = context.actorOf(Props[ChildActor2])
// val actor3 = context.actorSelection("akka.tcp://notExist")
val f1 = actor1 ! "hello"
val f2 = actor2 ! "hello"
val f3 = actor2 ! "hello"
// val f3 = actor3 ! "hello"
}
}
}