From 229b5e72058a644292d0f258bd0f7f06613b7b24 Mon Sep 17 00:00:00 2001 From: Tobe O Date: Wed, 1 May 2019 18:58:47 -0400 Subject: [PATCH] Fix travis --- CHANGELOG.md | 1 + analysis_options.yaml | 4 +-- example/main.dart | 2 +- lib/base_websocket_client.dart | 60 ++++++++++++++++++---------------- lib/server.dart | 8 ++--- lib/websocket_context.dart | 14 ++++---- test/service/common.dart | 4 ++- 7 files changed, 50 insertions(+), 43 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6361f7a3..9bd7428c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ # 2.0.3 * Remove `WebSocketController.plugin`. +* Remove any unawaited futures. # 2.0.2 * Update `stream_channel` to `2.0.0`. diff --git a/analysis_options.yaml b/analysis_options.yaml index 70257d27..380eebc8 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -1,6 +1,4 @@ include: package:pedantic/analysis_options.yaml analyzer: strong-mode: - implicit-casts: false - errors: - unawaited_futures: ignore \ No newline at end of file + implicit-casts: false \ No newline at end of file diff --git a/example/main.dart b/example/main.dart index e6757831..cf3746dc 100644 --- a/example/main.dart +++ b/example/main.dart @@ -46,7 +46,7 @@ main(List args) async { } var http2 = new AngelHttp2(app, ctx); - http2.onHttp1.forEach(http.handleRequest); + http2.onHttp1.listen(http.handleRequest); await http2.startServer('127.0.0.1', 3000); print('Listening at ${http2.uri}'); } else { diff --git a/lib/base_websocket_client.dart b/lib/base_websocket_client.dart index dca21459..143ce69e 100644 --- a/lib/base_websocket_client.dart +++ b/lib/base_websocket_client.dart @@ -95,13 +95,15 @@ abstract class BaseWebSocketClient extends BaseAngelClient { @override Future close() async { on._close(); - await _socket.sink.close(status.goingAway); - _onData.close(); - _onAllEvents.close(); - _onAuthenticated.close(); - _onError.close(); - _onServiceEvent.close(); - _onWebSocketChannelException.close(); + scheduleMicrotask(() async { + await _socket.sink.close(status.goingAway); + await _onData.close(); + await _onAllEvents.close(); + await _onAuthenticated.close(); + await _onError.close(); + await _onServiceEvent.close(); + await _onWebSocketChannelException.close(); + }); } /// Connects the WebSocket. [timeout] is optional. @@ -119,22 +121,24 @@ abstract class BaseWebSocketClient extends BaseAngelClient { } }); - getConnectedWebSocket().then((socket) { - if (!c.isCompleted) { - if (timer.isActive) timer.cancel(); + scheduleMicrotask(() { + return getConnectedWebSocket().then((socket) { + if (!c.isCompleted) { + if (timer.isActive) timer.cancel(); - while (_queue.isNotEmpty) { - var action = _queue.removeFirst(); - socket.sink.add(serialize(action)); + while (_queue.isNotEmpty) { + var action = _queue.removeFirst(); + socket.sink.add(serialize(action)); + } + + c.complete(socket); } - - c.complete(socket); - } - }).catchError((e, StackTrace st) { - if (!c.isCompleted) { - if (timer.isActive) timer.cancel(); - c.completeError(e, st); - } + }).catchError((e, StackTrace st) { + if (!c.isCompleted) { + if (timer.isActive) timer.cancel(); + c.completeError(e, st); + } + }); }); return await c.future.then((socket) { @@ -293,13 +297,13 @@ class WebSocketsService extends Service { } Future close() async { - _onAllEvents.close(); - _onCreated.close(); - _onIndexed.close(); - _onModified.close(); - _onRead.close(); - _onRemoved.close(); - _onUpdated.close(); + await _onAllEvents.close(); + await _onCreated.close(); + await _onIndexed.close(); + await _onModified.close(); + await _onRead.close(); + await _onRemoved.close(); + await _onUpdated.close(); } /// Serializes an [action] to be sent over a WebSocket. diff --git a/lib/server.dart b/lib/server.dart index 5b7c953b..734c2c35 100644 --- a/lib/server.dart +++ b/lib/server.dart @@ -387,7 +387,7 @@ class AngelWebSocket { var ws = await WebSocketTransformer.upgrade(req.rawRequest); var channel = new IOWebSocketChannel(ws); var socket = new WebSocketContext(channel, req, res); - handleClient(socket); + scheduleMicrotask(() => handleClient(socket)); return false; } else if (req is Http2RequestContext && res is Http2ResponseContext) { var connection = @@ -428,9 +428,9 @@ class AngelWebSocket { }); if (req.hasParsedBody) { - ctrl.local.sink.close(); + await ctrl.local.sink.close(); } else { - req.body.pipe(ctrl.local.sink); + await req.body.pipe(ctrl.local.sink); } var sink = utf8.encoder.startChunkedConversion(ctrl.foreign.sink); @@ -443,7 +443,7 @@ class AngelWebSocket { var ws = new WebSocketChannel(ctrl.foreign); var socket = new WebSocketContext(ws, req, res); - handleClient(socket); + scheduleMicrotask(() => handleClient(socket)); return false; } } else { diff --git a/lib/websocket_context.dart b/lib/websocket_context.dart index bcdca377..1876f8bd 100644 --- a/lib/websocket_context.dart +++ b/lib/websocket_context.dart @@ -40,12 +40,14 @@ class WebSocketContext { /// Closes the underlying [StreamChannel]. Future close() async { - await channel.sink.close(); - _onAction.close(); - _onAuthenticated.close(); - _onData.close(); - _onClose.add(null); - _onClose.close(); + scheduleMicrotask(() async { + await channel.sink.close(); + await _onAction.close(); + await _onAuthenticated.close(); + await _onData.close(); + await _onClose.add(null); + await _onClose.close(); + }); } /// Sends an arbitrary [WebSocketEvent]; diff --git a/test/service/common.dart b/test/service/common.dart index daae99d1..9d327860 100644 --- a/test/service/common.dart +++ b/test/service/common.dart @@ -1,3 +1,5 @@ +import 'dart:async'; + import 'package:angel_framework/angel_framework.dart'; import 'package:angel_model/angel_model.dart'; import 'package:angel_websocket/base_websocket_client.dart'; @@ -23,7 +25,7 @@ class TodoService extends MapService { testIndex(BaseWebSocketClient client) async { var todoService = client.service('api/todos'); - todoService.index(); + scheduleMicrotask(() => todoService.index()); var indexed = await todoService.onIndexed.first; print('indexed: $indexed');