【问题标题】:Can I delay my next line of code before it being execute?我可以在执行下一行代码之前延迟它吗?
【发布时间】:2012-01-28 03:20:09
【问题描述】:
我的 iOS 应用程序中有一个按钮,当我点击此按钮时,它会执行此操作:
- 调用 PHP Server 运行脚本(从 MySQL 查询数据库并将其重写为 SQLite 文件)
- 下载 xxx.sqlite 文件
所以有时当我的服务器滞后或变慢时,应用程序会在第一步尚未完成时下载,也许我需要一种方法来延迟代码,或者无论如何我可以检查文件是否完成了从 MySQL 到 SQLite 的转换文件?
感谢每个答案:)
【问题讨论】:
标签:
mysql
ios
sqlite
download
delay
【解决方案2】:
一种方法是做这样的事情
php 脚本:
unlink sqlite.file.md5
generate sqlite.file
calculate md5 sum of sqlite.file and output it in sqlite.file.md5
客户应该这样做:
download sqlite.file.md5
if not found:
wait some time and try again (in progress)
download sqlite.file
calculate md5 of sqlite.file and compare it with sqlite.file.md5
if there is a mismatch you probably downloaded in the middle of generation
实际上你不知道你需要延迟下载多少时间,你的 php 脚本也不知道(例如:取决于操作系统的调度程序,它可能会有点饿,每一代都可以在不同的时间间隔内完成)
你只能知道生成何时完成
编辑:
或者您可以在生成完成后在 sqlite 文件的末尾插入一条记录
然后检查它是否存在于下载的文件中