我如何在客户端使用“未来”?
而且,我如何阻止我的代码的执行,而没有事件被捕获?
import 'dart:html';
import 'dart:convert';
import 'dart:async';
Map data;
Future<String> ft_get_pseudo()
{
InputElement button;
InputElement text;
text = querySelector('[name="pseudo"]');
button = querySelector('[name="push"]');
button.onClick.listen((_) => text.value);
}
void main()
{
WebSocket wss;
String encode;
data = new Map();
wss = new WebSocket('ws://127.0.0.1:4040/ws');
ft_get_pseudo().then((name)
{
data['pseudo'] = name;
encode = JSON.encode(data);
wss.onOpen.listen((_) => wss.send(encode));
wss.onMessage.listen((msg) => print("Msg received : ${msg.data}"));
});
}
我在 ecmascript 6 中看到了 Promise 函数,有没有使用它的方法,或者想法?
HTML:
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<script type="application/dart" src="client.dart"></script>
<link rel="stylesheet" href="style.css" type="text/css">
<title>Client</title>
</head>
<body>
<div id="console">
</div>
<input type="text" name="pseudo" size="20" placeholder="pseudo">
<input type="button" name="push" value="Send">
</body>
</html>