我有一个函数需要传递给它的三个先前的承诺的结果.一个是线性相关的,另外两个可以同时运行.我想使用q.all来解决三个promise,然后使用.spread将结果传递给第四个.但是我的代码不起作用.任何帮助,将不胜感激.
var p1 = doWork(data);
var p2 = p1.then(doMoreWork);
var p3 = doConcurrentWork(data);
return q.all([p1,p2,p3]).spread(funcWith3params)
.fail(function(err) {
console.log(err):
}
Run Code Online (Sandbox Code Playgroud)
我可以在node-inspector中跟踪代码,看看是否正在调用前3个promise.但是,.spread调用的函数没有被调用.任何线索为什么?另外.fail也没被击中.
我正在尝试构建一个类,它将保存CSV文件中的一行数据及其标题信息.然后在课外,我正在制作这个类的元素的List <>.但是我得到的这个错误完全没用,"DynamicCSV不包含一个带有1个参数的构造函数." 事实上它实际上包含一个带有1个参数的构造函数.
class DynamicCSV : DynamicObject
{
public List<string> columnHeaders;
public List<string> rowData;
/* Constructor with 1 argument */
DynamicCSV(List<string> headers)
{
columnHeaders = new List<string>();
dynamic rowData = new List<string>();
columnHeaders = headers;
}
}
/* code that calls the constructor */
while (!streamReader.EndOfStream)
{
List<string> headers = new List<string>();
List<string> dataRow = new List<string>();
List<DynamicCSV> dataRows = new List<DynamicCSV>();
if (true == isHeaderRow)
{
currentRow = streamReader.ReadLine();
headers.AddRange(currentRow.Split(','));
dataRows.Add(new DynamicCSV(headers)); // here is the error
isHeaderRow = …
Run Code Online (Sandbox Code Playgroud)