Skip to content

Close Hot Reload listeners on exit #1775

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion build_runner/lib/src/server/server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class ServeHandler implements BuildState {
_state.buildResults.listen((result) {
_lastBuildResult = result;
_webSocketHandler.emitUpdateMessage(result);
});
}).onDone(_webSocketHandler.close);
}

@override
Expand Down Expand Up @@ -202,6 +202,12 @@ class BuildUpdatesWebSocketHandler {
connectionsByRootDir.remove(rootDir);
}
}

Future<void> close() {
return Future.wait(connectionsByRootDir.values
.expand((x) => x)
.map((connection) => connection.sink.close()));
}
}

shelf.Handler _injectBuildUpdatesClientCode(shelf.Handler innerHandler) {
Expand Down
7 changes: 7 additions & 0 deletions build_runner/test/server/serve_handler_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,13 @@ void main() {
await clientChannel1.sink.close();
});

test('closes listners', () async {
expect(clientChannel1.stream, emitsDone);
await createMockConnection(serverChannel1, 'web');
await handler.close();
expect(clientChannel1.closeCode, isNotNull);
});

test('emmits build results digests', () async {
_addSource('a|web/index.html', 'content1');
_addSource('a|lib/some.dart.js', 'content2');
Expand Down