gpt4 book ai didi

dart - Dart 太快了

转载 作者:行者123 更新时间:2023-12-03 03:02:53 29 4
gpt4 key购买 nike

我试图理解为什么这段代码两次打印“检查” ...

import 'dart:io';
import 'dart:async';
import 'dart:convert';

Future<Map> ft_get_data() {
File data;

data = new File("data.json");
return data.exists().then((value) {
if (!value) {
print("Data does no exist...\nCreating file...");
data.createSync();
print("Filling it...");
data.openWrite().write('{"index":{"content":"Helllo"}}');
print("Operation finish");
}
}).then((_) => data.readAsString()).then((content) => JSON.decode(content)
).catchError((e) => new Map());
}

void main() {
Map params;
String name;
num check = 0;

HttpServer.bind('127.0.0.1', 8080).then((server) {
print("Server is lauching... $server");
server.listen((HttpRequest request) {
request.response.statusCode = HttpStatus.ACCEPTED;
request.response.headers.contentType = new ContentType('text', 'htm l');
params = request.uri.queryParameters; // http://127.0.0.1:8080/?name=tristan
ft_get_data().then((data_map) {
name = data_map['index']['content'];
print('check: $check');
if (data_map.isNotEmpty) request.response.write(name); else
request.response.write('Booh');
check++;
}).whenComplete(request.response.close);
});
}).catchError((error) {
print("An error : $error.");
});
}

太快了吗?还是有一些方法可以暂停一下?谢谢。

最佳答案

我尝试了您的代码,并显示0

您正在使用哪个客户端访问服务器?

关于dart - Dart 太快了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22591841/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com