当我在听大量POST请求时,我正在尝试像方法论那样与Promise异步进行。
问题在于,它需要“ getDataLead”任务之外的返回值(这种情况下要取消对return "good2
”部分的注释)。
有什么想法可以使POST方法等待并返回异步“ matchLogic”函数的响应吗?
[HttpPost]
public async Task<string> Post([FromForm]string id)
{
String filterType = "id";
string filterValues = id;
int batchSize = 50;//max 300, default 300
String[] fields = { "email", "country", "city", "address", "postalCode", "phone", "company", "billingCountry", "billingCity", "billingPostalCode", "billingStreet", "mainPhone", "website" };//array of field names to retrieve
String nextPageToken = "";//paging token
Task<string> tr = await getDataLead(filterType, filterValues, batchSize, fields, nextPageToken).ContinueWith((t1) =>
{
if (t1.Exception == null)
{
getLeadsByFilterTypeRootObject data = JsonConvert.DeserializeObject<getLeadsByFilterTypeRootObject>(t1.Result);
if (data.success == true)
{
if (data.result.Count < 2)
{
return matchLogic(data.result[0]);
}
else
{
return Task.FromResult("not good");
}
}
else
{
return Task.FromResult("not good");
}
}
else
{
return Task.FromResult("not good");
}
});
// return "good2";
}
谢谢
答案 0 :(得分:0)
[HttpPost]
public async Task<string> Post([FromForm]string id)
{
String filterType = "id";
string filterValues = id;
Task<string> result = string.Empty;
int batchSize = 50;//max 300, default 300
String[] fields = { "email", "country", "city", "address", "postalCode", "phone", "company", "billingCountry", "billingCity", "billingPostalCode", "billingStreet", "mainPhone", "website" };//array of field names to retrieve
String nextPageToken = "";//paging token
Task<string> tr = await getDataLead(filterType, filterValues, batchSize, fields, nextPageToken).ContinueWith((t1) =>
{
if (t1.Exception == null)
{
getLeadsByFilterTypeRootObject data = JsonConvert.DeserializeObject<getLeadsByFilterTypeRootObject>(t1.Result);
if (data.success == true)
{
if (data.result.Count < 2)
{
result = matchLogic(data.result[0]);
}
else
{
result = Task.FromResult("not good");
}
}
else
{
result = Task.FromResult("not good");
}
}
else
{
result = Task.FromResult("not good");
}
});
return result;
}
这将强制您的应用程序从异步内容中获取值。