- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试在 Node.js 的循环内添加延迟。我有一个数组,需要为数组的每个元素调用一个函数。问题是每次这样的函数调用应该有 30 秒的间隔。这是我尝试过的 -
const cprRedshift = async (page) => {
let query = "select links from schema.table", links = [], ranks = []
let data = await redshiftSelect(query)
data.rows.forEach(element => {
links.push(element.links)
})
let hostnames = await getDomainNames(links)
// one way
for(let i = 0; i < hostnames.length; i++){
await setTimeout(async () => await checkPageRank(hostnames[i]), 30000)
}
// another way
let i = 0
while(i < hostnames.length){
await checkPageRank(page, hostnames[i])
setInterval(() => ++i, 30000)
}
}
checkPageRank
是同一脚本中的一个函数,我需要为 hostnames[] 数组中的所有元素调用它,同时在每次调用之间保持 30 秒的间隔。任何关于如何实现这一目标的想法将不胜感激。谢谢!
最佳答案
下面是执行此类操作的常见模式的简化示例:
const hostnames = ["one", "two", "three", "four", "five", "six"];
function go (index = 0) {
// do whatever you need to do for the current index.
console.log(hostnames[index]);
// if we haven't reached the end set a timeout
// to call this function again with the next index.
if (hostnames.length > index + 1) {
setTimeout(() => go(index + 1), 1000);
}
}
// kick it off
go();
关于javascript - 如何在循环内使用 JavaScript 创建 waitFor(delay) 函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56285655/
我在进程上使用 waitFor 命令时遇到问题。我的代码是这样的 //preconditions try{ // lock the work station Process p= Runtim
我正在尝试在 puppeteer 上运行我的第一个代码。 puppeteer v1.20.0 Node v8.11.3 Npm v5.6.0 这是一个基本示例,但它不起作用: const puppet
我有一个在 .jar 中编译的 Java 程序,因此最终用户实际上无法在控制台中直接按 ctrl+c。 他们必须在任务管理器中结束java进程。 但是,还有一种更简单的方法,不是吗? public c
我关注 a tutorial关于 react 测试。本教程有一个像这样的简单组件,用于展示如何测试异步操作: import React from 'react' const TestAsync = (
创建一个线程(TThreadStarter),然后它将创建许多工作线程,并且必须等待它们完成才能继续。它必须在 Linux 和 Windows 下都能工作。 下面的方法似乎是一个解决方案。但这是一件好
我试图找出T-SQL中WAITFOR的性能或内部实现,已经经历了MSDN Stackoverflow 和其他网站没有运气,这是我的问题 对于下面的代码,我想从表 DUMMY 中删除前 10,000 行
在 Windows 7 64 位上,运行 64 位 Java 1.7.0_17 ,下面显示的 p.waitFor() 永远不会返回。 String move_command="cmd.exe /c x
我正在尝试从命令行运行 Matlab 脚本,而我又从 Java 调用该脚本。我使用循环多次调用该脚本,并且在每次迭代中我希望我的 Java 程序暂停,直到 Matlab 脚本结束并退出 Matlab。
我正在尝试从 Java 运行命令行命令,快速的健全性检查让我意识到我遇到问题的原因是我无法获得下面的 pr.waitFor() 调用上类。该程序在不到 30 秒内结束,并且在“foo:”之后不打印任何
我正在构建一个应用程序,该应用程序应该在我的 Windows PC 上启动其他应用程序。当应用程序启动时,我的代码应该等到我关闭该程序才能继续执行。 System.out.println("Start
String command = "javac -cp .:../sqljdbc.jar SetHash.java"; Process child = Runtime.getRuntime().
我收到 16 位 MS-DOS 子系统错误,提示“为应用程序设置环境时出错。选择‘关闭’终止应用程序。”当我尝试运行一个应该下载程序的java小程序时。 这是源代码: if(getConfig(mai
我有一个 JAVA 代码,正在其中执行 perl 脚本。有些脚本不返回响应代码,但需要密码才能执行。在这些情况下,我的代码不会返回,并且 process.waitFor() 会无休止地等待。 有什么办
在运行外部脚本时,我想同时或分别读取该脚本的 ErrorStream 和 OutputStream,然后进一步处理它们。因此,我为其中一个流启动了一个 Thread。不幸的是,Process 似乎并没
我正在尝试使用 ProcessBuilder 来执行像“ls”命令这样简单的操作。我已经阅读了有关 waitFor() 调用返回之前需要消耗的进程流的问题,但即使错误重定向到输出并消耗流,进程也永远不
我在我的应用程序中使用以下代码... Process process = Runtime.getRuntime().exec( "perl " + perlScript + " " + pro
我正在尝试从 java 的 root android 设备中的/data/data 文件夹中获取所有文件和文件夹。我有在 Windows cmd 中正常工作的命令: adb -s shell su
以下代码总是返回 1。我不明白为什么。 String executeCmd[] = {"mysql"," -u" + dbUser," -p" + dbPass," -A"," -D"+dbName
我正在尝试运行 mysql 来执行来自 java 的一些文件。输入是从文件中读取的,应该通过管道传输到 mysql 进程中,一切似乎都正常,但是行 int exitCode = proc.waitFo
我对casperJS比较陌生。我有一个脚本,我想在页面B中执行操作(即验证用户的确认邮件),然后在页面A中继续执行。代码片段如下 casper.waitFor(function(){ retur
我是一名优秀的程序员,十分优秀!