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

Side by Side Diff: lib/src/runner/browser/server.dart

Issue 1260253005: Switch from AsyncThunk to AsyncMemoizer. (Closed) Base URL: git@github.com:dart-lang/test@master
Patch Set: Created 5 years, 4 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 unified diff | Download patch
« no previous file with comments | « lib/src/runner/browser/compiler_pool.dart ('k') | lib/src/runner/loader.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 library test.runner.browser.server; 5 library test.runner.browser.server;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:convert'; 8 import 'dart:convert';
9 import 'dart:io'; 9 import 'dart:io';
10 10
11 import 'package:async/async.dart'; 11 import 'package:async/async.dart';
12 import 'package:http_multi_server/http_multi_server.dart'; 12 import 'package:http_multi_server/http_multi_server.dart';
13 import 'package:path/path.dart' as p; 13 import 'package:path/path.dart' as p;
14 import 'package:pool/pool.dart'; 14 import 'package:pool/pool.dart';
15 import 'package:shelf/shelf.dart' as shelf; 15 import 'package:shelf/shelf.dart' as shelf;
16 import 'package:shelf/shelf_io.dart' as shelf_io; 16 import 'package:shelf/shelf_io.dart' as shelf_io;
17 import 'package:shelf_static/shelf_static.dart'; 17 import 'package:shelf_static/shelf_static.dart';
18 import 'package:shelf_web_socket/shelf_web_socket.dart'; 18 import 'package:shelf_web_socket/shelf_web_socket.dart';
19 19
20 import '../../backend/metadata.dart'; 20 import '../../backend/metadata.dart';
21 import '../../backend/suite.dart'; 21 import '../../backend/suite.dart';
22 import '../../backend/test_platform.dart'; 22 import '../../backend/test_platform.dart';
23 import '../../util/async_thunk.dart';
24 import '../../util/io.dart'; 23 import '../../util/io.dart';
25 import '../../util/one_off_handler.dart'; 24 import '../../util/one_off_handler.dart';
26 import '../../util/path_handler.dart'; 25 import '../../util/path_handler.dart';
27 import '../../util/stack_trace_mapper.dart'; 26 import '../../util/stack_trace_mapper.dart';
28 import '../../utils.dart'; 27 import '../../utils.dart';
29 import '../application_exception.dart'; 28 import '../application_exception.dart';
30 import '../load_exception.dart'; 29 import '../load_exception.dart';
31 import 'browser.dart'; 30 import 'browser.dart';
32 import 'browser_manager.dart'; 31 import 'browser_manager.dart';
33 import 'compiler_pool.dart'; 32 import 'compiler_pool.dart';
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 /// The pool of active `pub serve` compilations. 116 /// The pool of active `pub serve` compilations.
118 /// 117 ///
119 /// Pub itself ensures that only one compilation runs at a time; we just use 118 /// Pub itself ensures that only one compilation runs at a time; we just use
120 /// this pool to make sure that the output is nice and linear. 119 /// this pool to make sure that the output is nice and linear.
121 final _pubServePool = new Pool(1); 120 final _pubServePool = new Pool(1);
122 121
123 /// The HTTP client to use when caching JS files in `pub serve`. 122 /// The HTTP client to use when caching JS files in `pub serve`.
124 final HttpClient _http; 123 final HttpClient _http;
125 124
126 /// Whether [close] has been called. 125 /// Whether [close] has been called.
127 bool get _closed => _closeThunk.hasRun; 126 bool get _closed => _closeMemo.hasRun;
128 127
129 /// The thunk for running [close] exactly once. 128 /// The memoizer for running [close] exactly once.
130 final _closeThunk = new AsyncThunk(); 129 final _closeMemo = new AsyncMemoizer();
131 130
132 /// All currently-running browsers. 131 /// All currently-running browsers.
133 /// 132 ///
134 /// These are controlled by [_browserManager]s. 133 /// These are controlled by [_browserManager]s.
135 final _browsers = new Map<TestPlatform, Browser>(); 134 final _browsers = new Map<TestPlatform, Browser>();
136 135
137 /// A map from browser identifiers to futures that will complete to the 136 /// A map from browser identifiers to futures that will complete to the
138 /// [BrowserManager]s for those browsers, or the errors that occurred when 137 /// [BrowserManager]s for those browsers, or the errors that occurred when
139 /// trying to load those managers. 138 /// trying to load those managers.
140 /// 139 ///
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 default: 462 default:
464 throw new ArgumentError("$browser is not a browser."); 463 throw new ArgumentError("$browser is not a browser.");
465 } 464 }
466 } 465 }
467 466
468 /// Closes the server and releases all its resources. 467 /// Closes the server and releases all its resources.
469 /// 468 ///
470 /// Returns a [Future] that completes once the server is closed and its 469 /// Returns a [Future] that completes once the server is closed and its
471 /// resources have been fully released. 470 /// resources have been fully released.
472 Future close() { 471 Future close() {
473 return _closeThunk.run(() async { 472 return _closeMemo.runOnce(() async {
474 var futures = _browsers.values.map((browser) => browser.close()).toList(); 473 var futures = _browsers.values.map((browser) => browser.close()).toList();
475 474
476 futures.add(_server.close()); 475 futures.add(_server.close());
477 futures.add(_compilers.close()); 476 futures.add(_compilers.close());
478 477
479 await Future.wait(futures); 478 await Future.wait(futures);
480 479
481 if (_pubServeUrl == null) { 480 if (_pubServeUrl == null) {
482 new Directory(_compiledDir).deleteSync(recursive: true); 481 new Directory(_compiledDir).deleteSync(recursive: true);
483 } else { 482 } else {
484 _http.close(); 483 _http.close();
485 } 484 }
486 }); 485 });
487 } 486 }
488 } 487 }
OLDNEW
« no previous file with comments | « lib/src/runner/browser/compiler_pool.dart ('k') | lib/src/runner/loader.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698