加权轮询与轮询区别
In an ideal world, we wouldn't have to poll for anything; we would always have events to trigger other functions. This isn't an ideal world, however, so it's important to know how to poll in multiple programming languages. I've covered JavaScript polling (with and without Promises), but what about command line polling? For example, ensuring MYSQL is up before attempting to perform more operations.
在理想的世界中,我们无需轮询任何东西。 我们总是会有事件触发其他功能。 但是,这不是一个理想的世界,因此了解如何以多种编程语言进行轮询非常重要。 我已经介绍了JavaScript轮询 (带有和不带有Promises ),但是命令行轮询呢? 例如,在尝试执行更多操作之前,请确保MYSQL已启动。
Here's the basic syntax:
基本语法如下:
# while ! (command here); do
while ! mysql -uroot; do
sleep 1
done
The example above performs the mysql -uroot
operation (which will fail until mysqld
is up) every second. Keep in mind the poll operation you run should be as simple as possible, just enough to know that what you want to use is available!
上面的示例mysql -uroot
执行一次mysql -uroot
操作(直到mysqld
启动,该操作将失败)。 请记住,您运行的轮询操作应尽可能简单,足以知道您要使用的功能可用!
加权轮询与轮询区别