0
我試圖以5秒爲間隔運行'checkServer'。然而'服務器很好'只運行一次。重複該功能需要做什麼?Dart服務器檢查時間間隔
import 'dart:io';
import 'dart:uri';
import 'dart:isolate';
checkServer() {
HttpClient client = new HttpClient();
HttpClientConnection connection = client.getUrl(...);
connection.onResponse = (res) {
...
print('server is fine');
//client.shutdown();
};
connection.onError = ...;
}
main() {
new Timer.repeating(5000, checkServer());
}
謝謝。現在我明白了Timer語法。 – basheps