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); |
+ }); |
} |
} |