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

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

Issue 221173007: Properly handle web socket requests to half-initialized servers. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: code review Created 6 years, 9 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/lib/src/barback/build_environment.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/build_directory.dart
diff --git a/sdk/lib/_internal/pub/lib/src/barback/build_directory.dart b/sdk/lib/_internal/pub/lib/src/barback/build_directory.dart
index 19fd2edef20673e53234add5075e388c6220577e..c01da046dc1eaf49195f2280a0e4f72161888755 100644
--- a/sdk/lib/_internal/pub/lib/src/barback/build_directory.dart
+++ b/sdk/lib/_internal/pub/lib/src/barback/build_directory.dart
@@ -21,9 +21,18 @@ class BuildDirectory {
/// The relative directory path within the package.
final String directory;
+ /// The hostname to serve this directory on.
+ final String hostname;
+
+ /// The port to serve this directory on.
+ final int port;
+
/// The server bound to this directory.
- BarbackServer get server => _server;
- BarbackServer _server;
+ ///
+ /// This is a future that will complete once [serve] has been called and the
+ /// server has been successfully spun up.
+ Future<BarbackServer> get server => _serverCompleter.future;
+ final _serverCompleter = new Completer<BarbackServer>();
/// The subscription to the [DirectoryWatcher] used to watch this directory
/// for changes.
@@ -31,26 +40,31 @@ class BuildDirectory {
/// If the directory is not being watched, this will be `null`.
StreamSubscription<WatchEvent> watchSubscription;
- BuildDirectory(this._environment, this.directory);
+ BuildDirectory(this._environment, this.directory, this.hostname, this.port);
/// Binds a server running on [hostname]:[port] to this directory.
- Future<BarbackServer> serve(String hostname, int port) {
+ Future<BarbackServer> serve() {
return BarbackServer.bind(_environment, hostname, port, directory)
- .then((server) => _server = server);
+ .then((server) {
+ _serverCompleter.complete(server);
+ return server;
+ });
}
/// Removes the build directory from the build environment.
///
/// Closes the server, removes the assets from barback, and stops watching it.
Future close() {
- var futures = [server.close()];
+ return server.then((server) {
+ var futures = [server.close()];
- // Stop watching the directory.
- if (watchSubscription != null) {
- var cancel = watchSubscription.cancel();
- if (cancel != null) futures.add(cancel);
- }
+ // Stop watching the directory.
+ if (watchSubscription != null) {
+ var cancel = watchSubscription.cancel();
+ if (cancel != null) futures.add(cancel);
+ }
- return Future.wait(futures);
+ return Future.wait(futures);
+ });
}
}
« no previous file with comments | « no previous file | sdk/lib/_internal/pub/lib/src/barback/build_environment.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698