Dart is too fast -
i'm trying understand why code print "check" twice...
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 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 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."); }); }
is fast ? or there exist method make pause ? thank you.
i tried code , prints 0
.
what client using access server?
Comments
Post a Comment