补充一下赵老师,我怕您仍旧看不明白,我的router函数如下,indexAsync函数见上封邮件末尾。我这么调用我总的结果,您可以看见,我把res传进indexAsync去,让res.send结果。这样是可行的
router2 = (req, res, next) ->
indexAsync(id, report, res).start()
server = Restify.createServer()
server.get path2, router2
如果我希望在router2里直接拿取到 indexAsync的结果进行操作,就必须把router2改成
router2Async = eval(Jscex.compile("async", (req, res, next) ->
data = $await(getResultsReportAsync(id, report, res))
res.send data))
server.get path2, router2Async.start()
但是这样是行不通的,他报错Task can only be started in \"ready\" status
我想知道除了把一函数定义成Jscex异步函数,再在其中用$await获取数据,还有别的方法吗?
我调用一个Jscex异步函数除了start还有什么?
非常感谢您,希望我能够表示得比前几次好一点。如果您哪个地方觉得我没说清楚的话,可以告诉我。
zili
2012/3/26 Zi LI
<auror...@gmail.com>
您好,赵老师,我已经用您的方法做出来了代码在下边,您的方法非常好。但是我更感兴趣的是,我能否在回调函数或者Jscex异步方法外获得每次查询所得结果,就像我上封信里说的怎么获得datalist呢?我的意思是,比如现在要在一个Jscex方法里用 Results = $await(loadDataAsync allquery)获取数据Results,如果不在Jscex方法里是没有办法使用$await对吗?还有我需要使用一个Jscex方法,必须要用start()?比如我在路由里这样调用indexAsync(id, report, res).start()。我把res作为参数传给了indexAsync去操作结果,让他把结果发到网页。
但是如果我能把结果比如dataList从indexAsync里提取出来,而不是indexAsync里操作结果。我希望直接在其他地方操作这个结果。您能明白我的意思吗?请问Jscex或者node.js有这样的方法吗?
麻烦您了,不胜感激!我的代码如下
loadDataAsync = eval(Jscex.compile("async", (allquery) ->
dataList = []
console.log 'query'
console.log allquery
for query in allquery
data = $await(requestEngine.searchAsync query)
dataList.push(data)
return dataList))
loadPathNameAsync = eval(Jscex.compile("async", (allquery) ->
data = $await(loadDataAsync allquery)
pathNameList = []
pathListWithCount = data[0].facets.pathList.terms
for eachPath in pathListWithCount
pathName = eachPath.term
pathNameList.push pathName
return pathNameList
))
indexAsync = eval(Jscex.compile("async", (id, report, res) ->
build = new BuildQuery(id)
allquery = build.getQueryFromReport(id, report)
result = {}
result.AllOthers_Results = $await(loadDataAsync allquery)
must_array = build.getMustArrayOfPath report
if must_array isnt []
must_array = build.getMustArrayOfPath report
queryPath = build.getPathQuery(id, must_array)
queries = [queryPath]
pathNameList = $await(loadPathNameAsync queries)
allquery_progress=[]
for pathName in pathNameList
query_array = build.getProgressQuery(pathName)
for eachquery in query_array
allquery_progress.push eachquery
result.ProgressData = $await(loadDataAsync allquery_progress)
res.send result))