OLD | NEW |
---|---|
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 import 'package:analysis_server/src/channel.dart'; | 9 import 'package:analysis_server/src/channel.dart'; |
9 import 'package:analysis_server/src/domain_server.dart'; | 10 import 'package:analysis_server/src/domain_server.dart'; |
10 import 'package:analysis_server/src/protocol.dart'; | 11 import 'package:analysis_server/src/protocol.dart'; |
11 | 12 |
12 /** | 13 /** |
13 * [AnalysisManager] is used to launch and manage an analysis server | 14 * [AnalysisManager] is used to launch and manage an analysis server |
14 * running in a separate process using either the [start] or [connect] methods. | 15 * running in a separate process using either the [start] or [connect] methods. |
15 */ | 16 */ |
16 class AnalysisManager { | 17 class AnalysisManager { |
17 // TODO dynamically allocate port and/or allow client to specify port | 18 // TODO dynamically allocate port and/or allow client to specify port |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
110 | 111 |
111 /** | 112 /** |
112 * Stop the analysis server. | 113 * Stop the analysis server. |
113 * | 114 * |
114 * Returns `true` if the signal is successfully sent and process terminates. | 115 * Returns `true` if the signal is successfully sent and process terminates. |
115 * Otherwise there was no attached process or the signal could not be sent, | 116 * Otherwise there was no attached process or the signal could not be sent, |
116 * usually meaning that the process is already dead. | 117 * usually meaning that the process is already dead. |
117 */ | 118 */ |
118 Future<bool> stop() { | 119 Future<bool> stop() { |
119 if (process == null) { | 120 if (process == null) { |
121 channel.close(); | |
Bob Nystrom
2014/03/04 01:03:45
This should probably be async too:
return channel
danrubel
2014/03/05 15:32:04
Good point. Updated close() to return a Future and
nweiz
2014/03/05 20:16:39
Also below.
danrubel
2014/03/11 19:06:09
Done.
| |
120 return new Future.value(false); | 122 return new Future.value(false); |
121 } | 123 } |
122 var request = new Request('0', ServerDomainHandler.SHUTDOWN_METHOD); | 124 return channel |
123 channel.sendRequest(request); | 125 .sendRequest(new Request('0', ServerDomainHandler.SHUTDOWN_METHOD)) |
124 return process.exitCode | 126 .timeout(new Duration(seconds: 2), onTimeout: () { |
125 .timeout(new Duration(seconds: 10)) | 127 print('Expected shutdown response'); |
126 .catchError((error) { | 128 }) |
129 .then((Response response) { | |
130 channel.close(); | |
131 return process.exitCode; | |
132 }) | |
133 .timeout(new Duration(seconds: 2), onTimeout: () { | |
134 print('Expected server to shutdown'); | |
127 process.kill(); | 135 process.kill(); |
128 throw 'Expected server to shutdown'; | |
129 }) | 136 }) |
130 .then((result) { | 137 .then((int result) { |
131 if (result != 0) { | 138 if (result != null && result != 0) { |
132 exitCode = result; | 139 exitCode = result; |
133 } | 140 } |
134 return true; | 141 return true; |
135 }); | 142 }); |
Bob Nystrom
2014/03/04 01:03:45
The logic looks good here, but I would format it l
danrubel
2014/03/05 15:32:04
I find the wrapped style makes it harder to read t
| |
136 } | 143 } |
137 | |
138 } | 144 } |
OLD | NEW |