Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(624)

Unified Diff: sdk/lib/_internal/pub/lib/src/barback/web_socket_api.dart

Issue 310053004: Add an exitOnClose function to the "pub serve" WebSocket API. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | sdk/lib/_internal/pub/test/serve/utils.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/_internal/pub/lib/src/barback/web_socket_api.dart
diff --git a/sdk/lib/_internal/pub/lib/src/barback/web_socket_api.dart b/sdk/lib/_internal/pub/lib/src/barback/web_socket_api.dart
index 1a1eefb167055ffca09c180abf7e07bcb4a47119..ff6bb910a14ca325b0c0b3a5e13ad9e3945e7c51 100644
--- a/sdk/lib/_internal/pub/lib/src/barback/web_socket_api.dart
+++ b/sdk/lib/_internal/pub/lib/src/barback/web_socket_api.dart
@@ -11,6 +11,9 @@ import 'package:http_parser/http_parser.dart';
import 'package:path/path.dart' as path;
import 'package:json_rpc_2/json_rpc_2.dart' as json_rpc;
+import '../exit_codes.dart' as exit_codes;
+import '../io.dart';
+import '../log.dart' as log;
import '../utils.dart';
import 'asset_environment.dart';
@@ -24,11 +27,20 @@ class WebSocketApi {
final AssetEnvironment _environment;
final _server = new json_rpc.Server();
+ /// Whether the application should exit when this connection closes.
+ bool _exitOnClose = false;
+
WebSocketApi(this._socket, this._environment) {
_server.registerMethod("urlToAssetId", _urlToAssetId);
_server.registerMethod("pathToUrls", _pathToUrls);
_server.registerMethod("serveDirectory", _serveDirectory);
_server.registerMethod("unserveDirectory", _unserveDirectory);
+
+ /// Tells the server to exit as soon as this WebSocket connection is closed.
+ ///
+ /// This takes no arguments and returns no results. It can safely be called
+ /// as a JSON-RPC notification.
+ _server.registerMethod("exitOnClose", () => _exitOnClose = true);
}
/// Listens on the socket.
@@ -41,7 +53,11 @@ class WebSocketApi {
_server.parseRequest(request).then((response) {
if (response != null) _socket.add(response);
});
- }, cancelOnError: true).asFuture();
+ }, cancelOnError: true).asFuture().then((_) {
+ if (!_exitOnClose) return;
+ log.message("WebSocket connection closed, terminating.");
+ flushThenExit(exit_codes.SUCCESS);
+ });
}
/// Given a URL to an asset that is served by pub, returns the ID of the
« no previous file with comments | « no previous file | sdk/lib/_internal/pub/test/serve/utils.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698