Dart等待关键字

Ele*_*ron 2 dart dart-io dart-async dart-sdk dart-rpc

我想使用io示例尝试使用Dart的rpc包(https://github.com/dart-lang/rpc)

我在64位版本的Dart编辑器上使用1.9.1 sdk(无法更新更多稳定版本)

这是我的pubspec.yaml:

name: myDartRestServer
version: 0.0.1
description: A minimal command-line application.
#author: <your name> <email@example.com>
#homepage: https://www.example.com
environment:
  sdk: '1.9.1'
dependencies: 
  rpc: any
dev_dependencies:
  unittest: any
Run Code Online (Sandbox Code Playgroud)

但是当我尝试复制样本以启动我的服务器时:

final ApiServer _apiServer = new ApiServer('/api/', prettyPrint: true);

void start() {
    _apiServer.addApi(new Synchro());
    HttpServer server = await HttpServer.bind(InternetAddress.ANY_IP_V4, 9090);
    server.listen(_apiServer.httpRequestHandler);
    _apiServer.enableDiscoveryApi("http://localhost:9090");
}
Run Code Online (Sandbox Code Playgroud)

我的EDI(SDK)不知道await关键字.(我在我的库文件中导入了dart:io dart:async和rpc包)

我错过了什么?感谢您提前回复.祝你今天愉快.

Gün*_*uer 6

您需要将该功能标记为async能够使用await

void start() async {
  ....
Run Code Online (Sandbox Code Playgroud)

试试DartPad

没有async await是有效的标识符.