OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 import 'dart:async'; | 5 import 'dart:async'; |
6 import 'dart:convert'; | 6 import 'dart:convert'; |
7 import 'dart:io'; | 7 import 'dart:io'; |
8 | 8 |
9 import 'package:async/async.dart'; | 9 import 'package:async/async.dart'; |
10 import 'package:http_multi_server/http_multi_server.dart'; | 10 import 'package:http_multi_server/http_multi_server.dart'; |
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 // Capture errors and release them later to avoid Zone issues. This call to | 378 // Capture errors and release them later to avoid Zone issues. This call to |
379 // [_browserManagerFor] is running in a different [LoadSuite] than future | 379 // [_browserManagerFor] is running in a different [LoadSuite] than future |
380 // calls, which means they're also running in different error zones so | 380 // calls, which means they're also running in different error zones so |
381 // errors can't be freely passed between them. Storing the error or value as | 381 // errors can't be freely passed between them. Storing the error or value as |
382 // an explicit [Result] fixes that. | 382 // an explicit [Result] fixes that. |
383 _browserManagers[platform] = Result.capture(future); | 383 _browserManagers[platform] = Result.capture(future); |
384 | 384 |
385 return future; | 385 return future; |
386 } | 386 } |
387 | 387 |
| 388 /// Close all the browsers that the server currently has open. |
| 389 /// |
| 390 /// Note that this doesn't close the server itself. Browser tests can still be |
| 391 /// loaded, they'll just spawn new browsers. |
| 392 Future closeBrowsers() { |
| 393 var managers = _browserManagers.values.toList(); |
| 394 _browserManagers.clear(); |
| 395 return Future.wait(managers.map((manager) async { |
| 396 var result = await manager; |
| 397 if (result.isError) return; |
| 398 await result.asValue.value.close(); |
| 399 })); |
| 400 } |
| 401 |
388 /// Closes the server and releases all its resources. | 402 /// Closes the server and releases all its resources. |
389 /// | 403 /// |
390 /// Returns a [Future] that completes once the server is closed and its | 404 /// Returns a [Future] that completes once the server is closed and its |
391 /// resources have been fully released. | 405 /// resources have been fully released. |
392 Future close() { | 406 Future close() { |
393 return _closeMemo.runOnce(() async { | 407 return _closeMemo.runOnce(() async { |
394 var futures = _browserManagers.values.map((future) async { | 408 var futures = _browserManagers.values.map((future) async { |
395 var result = await future; | 409 var result = await future; |
396 if (result.isError) return; | 410 if (result.isError) return; |
397 | 411 |
398 await result.asValue.value.close(); | 412 await result.asValue.value.close(); |
399 }).toList(); | 413 }).toList(); |
400 | 414 |
401 futures.add(_server.close()); | 415 futures.add(_server.close()); |
402 futures.add(_compilers.close()); | 416 futures.add(_compilers.close()); |
403 | 417 |
404 await Future.wait(futures); | 418 await Future.wait(futures); |
405 | 419 |
406 if (_config.pubServeUrl == null) { | 420 if (_config.pubServeUrl == null) { |
407 new Directory(_compiledDir).deleteSync(recursive: true); | 421 new Directory(_compiledDir).deleteSync(recursive: true); |
408 } else { | 422 } else { |
409 _http.close(); | 423 _http.close(); |
410 } | 424 } |
411 }); | 425 }); |
412 } | 426 } |
413 } | 427 } |
OLD | NEW |