【发布时间】:2014-11-30 01:13:58
【问题描述】:
我正在寻找组织以下代码的最佳方法
这是 1.0 版,返回未来的最佳方式是什么
class ComparePrepMgr(factory:IFactoryBuilder) {
val daoact = factory.actorFactory.getActor[DAOSupervisor] //Returns Option[IActorURI]
def prepare(testplan:TestPlan) : Future[UnitofWorkRequest] =
{
for ( dao <- daoact;
testcase <- testplan.testcases; //Returns testcase instance from list type
sourceenvfut = getFuture[Vector[EnvironmentInfo]](dao, queryDAO[EnvironmentInfo](new DataQueryExp(ObjectIdEqOp("_id",testcase.sourceenv,false),None))) ;
destenvfut = getFuture[Vector[EnvironmentInfo]](dao, queryDAO[EnvironmentInfo](new DataQueryExp(ObjectIdEqOp("_id",testcase.destenv ,false),None))) ;
sourceobjfut = getFuture[Vector[ObjectInfo]](dao, queryDAO[ObjectInfo](new DataQueryExp(ObjectIdEqOp("_id",testcase.source,false),None))) ;
destobjfut = getFuture[Vector[ObjectInfo]](dao, queryDAO[ObjectInfo](new DataQueryExp(ObjectIdEqOp("_id",testcase.destination ,false),None)));
sourceenv <- sourceenvfut;destenv <- destenvfut; sourceobj <- sourceobjfut; destobj <- destobjfut
)
{
UnitofWorkRequest(testplan.copy(testcases = List()) , testcase, sourceenv.last, destenv.last, sourceobj.last,destobj.last)
}
这是代码的另一种变体,但它迫使我分解我的函数 b/c。我正在根据类似的返回类型安排理解,因此我对上面的代码感兴趣
class ComparePrepMgr(factory:IFactoryBuilder) {
val daoact = factory.actorFactory.getActor[DAOSupervisor]
def prepare(testplan:TestPlan) =
{
for ( testcase <- testplan.testcases;
dao <- daoact
) yield prepareFuture(testplan,dao,testcase)
}
def prepareFuture(testplan:TestPlan,dao:IActorURI,testcase:TestCaseInfo) =
{
for ( sourceenv<- getFuture[Vector[EnvironmentInfo]](dao, queryDAO[EnvironmentInfo](new DataQueryExp(ObjectIdEqOp("_id",testcase.sourceenv,false),None)));
destenv <- getFuture[Vector[EnvironmentInfo]](dao, queryDAO[EnvironmentInfo](new DataQueryExp(ObjectIdEqOp("_id",testcase.destenv ,false),None)));
sourceobj <- getFuture[Vector[ObjectInfo]](dao, queryDAO[ObjectInfo](new DataQueryExp(ObjectIdEqOp("_id",testcase.source,false),None))) ;
destobj <- getFuture[Vector[ObjectInfo]](dao, queryDAO[ObjectInfo](new DataQueryExp(ObjectIdEqOp("_id",testcase.destination ,false),None)))
) yield UnitofWorkRequest(testplan.copy(testcases = List()) , testcase, sourceenv.last, destenv.last, sourceobj.last,destobj.last)
}
}
感谢您在使 1.0 版正常工作方面的任何帮助。
【问题讨论】:
标签: scala future scala-2.10