当我正在收听大量 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";
}
谢谢