Chromium Code Reviews| Index: runtime/bin/process_impl.dart |
| diff --git a/runtime/bin/process_impl.dart b/runtime/bin/process_impl.dart |
| index 47ccd8d8ff386aad0014c91a082ef125a392ca57..fa7f7238e559e16f6f86fa0a0c726c2e06a0e25a 100644 |
| --- a/runtime/bin/process_impl.dart |
| +++ b/runtime/bin/process_impl.dart |
| @@ -14,12 +14,26 @@ class _Process extends NativeFieldWrapperClass1 implements Process { |
| static Future<ProcessResult> run(String path, |
| List<String> arguments, |
| [ProcessOptions options]) { |
| - return new _NonInteractiveProcess._start(path, arguments, options)._result; |
| + return new _NonInteractiveProcess(path, arguments, options)._result; |
| } |
| - _Process.start(String path, |
| - List<String> arguments, |
| - ProcessOptions options) { |
| + static Future<Process> start(String path, |
| + List<String> arguments, |
| + ProcessOptions options) { |
| + Completer completer = new Completer(); |
| + _Process process = new _Process(path, arguments, options); |
| + process._onStart = () { |
| + process._onError = null; |
| + completer.complete(process); |
| + }; |
| + process._onError = (e) { |
| + process._onError = null; |
| + completer.completeException(e); |
| + }; |
| + return completer.future; |
| + } |
| + |
| + _Process(String path, List<String> arguments, ProcessOptions options) { |
| if (path is !String) { |
| throw new ArgumentError("Path is not a String: $path"); |
| } |
| @@ -227,19 +241,10 @@ class _Process extends NativeFieldWrapperClass1 implements Process { |
| throw new ArgumentError( |
| "Argument 'signal' must be a ProcessSignal"); |
| } |
| - if (!_started) { |
| - var e = new ProcessException("Cannot kill process that is not started"); |
| - _reportError(e); |
| - return; |
| - } |
| - if (_ended) { |
| - return; |
| - } |
| - if (_kill(this, signal._signalNumber)) { |
| - return; |
| - } |
| - _reportError(new ProcessException("Could not kill process")); |
| - return; |
| + assert(_started); |
| + if (_ended) return; |
| + if (_kill(this, signal._signalNumber)) return; |
| + throw new ProcessException("Could not kill process"); |
|
Anders Johnsen
2012/10/12 08:53:11
Maybe change exception to "Could not send kill sig
Mads Ager (google)
2012/10/12 08:56:25
And an error message about signals is not very Win
Anders Johnsen
2012/10/12 08:58:10
Hehe agreed, but if we mention both 'kill' and 'si
|
| } |
| bool _kill(Process p, int signal) native "Process_Kill"; |
| @@ -265,14 +270,6 @@ class _Process extends NativeFieldWrapperClass1 implements Process { |
| _onExit = callback; |
| } |
| - void set onError(void callback(e)) { |
| - _onError = callback; |
| - } |
| - |
| - void set onStart(void callback()) { |
| - _onStart = callback; |
| - } |
| - |
| void _reportError(e) { |
|
Søren Gjesse
2012/10/12 11:44:04
This is not used any more - right?
Mads Ager (google)
2012/10/12 11:50:26
It is still used internally to report startup erro
|
| if (_onError != null) { |
| _onError(e); |
| @@ -304,9 +301,9 @@ class _Process extends NativeFieldWrapperClass1 implements Process { |
| // _NonInteractiveProcess is used to implement the Process.run |
| // method. |
| class _NonInteractiveProcess { |
| - _NonInteractiveProcess._start(String path, |
| - List<String> arguments, |
| - ProcessOptions options) { |
| + _NonInteractiveProcess(String path, |
| + List<String> arguments, |
| + ProcessOptions options) { |
| _completer = new Completer<ProcessResult>(); |
| // Extract output encoding options and verify arguments. |
| var stdoutEncoding = Encoding.UTF_8; |
| @@ -329,13 +326,13 @@ class _NonInteractiveProcess { |
| } |
| // Start the underlying process. |
| - _process = new _Process.start(path, arguments, options); |
| + _process = new _Process(path, arguments, options); |
| // Make sure stdin is closed. |
| - _process.onStart = _process.stdin.close; |
| + _process._onStart = _process.stdin.close; |
| // Setup process error handling. |
| - _process.onError = (e) => _completer.completeException(e); |
| + _process._onError = (e) => _completer.completeException(e); |
| // Setup process exit handling. |
| _process.onExit = (exitCode) { |