English 中文(简体)
是否在同样的文书中执行同文法。 正如同仁法一样,所有方面都没有任何业绩效益?
原标题:Does executing sync code in the same Promise.all as async code have any performance benefit?

我有一 piece。 报告从3个不同的终点点收集数据。 这是第一步。

const keys = [ a ,  b ,  c ];

const getDataFromEndpoint = async (key) => { 
  return await ... ;
};

const [result1, result2, result3] = await Promise.all(keys.map(key => getDataFromEndpoint(key)));

这里没有按照预期使用Promise.all的问题。

然后,在第二步,它从另一个终点收到另一份报告。 还必须将数据与第一步合并,以开展一些过于仓促的行动。

EDIT: 订单的转换,因此,先称作“星号”功能

const mergeResults = (arrayOfResults) => {
  return arrayOfResults.reduce( ... );
};

const anotherKey =  d ;

const [result4, mergedResults] = Promise.all([
  getDataFromEndpoint(anotherKey),
  mergeResults([result1, result2, result3]),
]);

这是否有效运用了“同时”的同仁呼吁正在等待答复? 如果是的话,这种表现比将辛迪加法列入普罗姆萨尔岛还要多?

我已经利用“智慧”实施。 我根本不知道它是否发挥作用。

问题回答

这是否有效运用了“同时”的同仁呼吁正在等待答复?

Sort of.

。 然后,控制流量将转至下一个主要翻新作业<代码>合并后([结果1,结果2,结果3]

你们再通过<代码>Promise.all(<>>>/code>的阵列,在后者完成之前就已经实现。

表现比将辛迪加法列入ise。 所有这一切?

业绩差异可能微乎其微,但你确实有某种混淆代码和错误使用<代码>Promise.all(<>。

您也可以使用功能上相同的内容。

const results = await Promise.all(keys.map(getDataFromEndpoint));

// Start the other endpoint request
const p4 = getDataFromEndpoint( d ); // note: no `await`

const mergedResults = mergeResults(results);
const result4 = await p4; // now await the result




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签