我正在运行一个线程,它可以做一些事情.
-
它从API获取浮点数
-
将该数字追加到文件中
-
将该号码打印到命令终端
-
重复
price_file = File.open(price_file, "w+") $time = Thread.new { while true price = Api.new.api(nil) price_file << price price_file << " " puts price sleep(seconds) end }
只有在我终止循环或程序后,价格或数字才会出现在文件中. 我希望能够在程序仍在运行的同时对添加到文件中的数字运行一些函数.