javascript - Make function calls sequentially from a array of objects without waiting for result
问题描述
I have an array of objects. For all the objects inside that array, i have to execute a series of function and that result should be sent back to callee. I want to execute these functions for those objects sequentially or paralleled without waiting for the result.
for example: I have
const arr = [{...},{...},{...},...{...}];
function exeArr(obj) {
function f1(){...},
function f2(){...}
return result
}
解决方案
使用异步代码执行setTimeout
:
setTimeout(() => exeArr(obj), 0);
setTimeout(f1, 0);
setTimeout(f2, 0);
...
推荐阅读
- python - 单个范围语句中的多个循环,Python Selenium
- javascript - 如何解决依赖问题:“npm run dev”不起作用
- javascript - Puppeteer 对 args 的困惑
- symfony - 用于夹具生成的自定义代理实体
- xcode - Xcode 界面生成器显示“无选择”
- powershell - 子生成的powershell脚本完成后如何继续powershell脚本?
- python - 我正在寻找在 python 中生成列表列表的组合
- python - Django Admin自定义列表过滤不同的模型
- java - 如何解决 - 如果应用程序未打开一段时间,Onesignal 推送通知不会发送到 Android 设备?
- x11 - 为 X2Go 客户端设置一致的显示编号