Chromium Code Reviews| Index: mojo/public/dart/src/event_stream.dart |
| diff --git a/mojo/public/dart/src/event_stream.dart b/mojo/public/dart/src/event_stream.dart |
| index 9c8321709332fe05ab77edf1ca35dabf13b2dba9..268a5d431adce7135dc878ba117af3c93ecbb9c2 100644 |
| --- a/mojo/public/dart/src/event_stream.dart |
| +++ b/mojo/public/dart/src/event_stream.dart |
| @@ -124,7 +124,7 @@ class MojoEventStream extends Stream<List<int>> { |
| } |
| abstract class Listener { |
| - StreamSubscription<List<int>> listen({Function onClosed}); |
| + StreamSubscription<List<int>> listen(); |
| } |
| class MojoEventStreamListener { |
| @@ -133,25 +133,20 @@ class MojoEventStreamListener { |
| bool _isOpen = false; |
| bool _isInHandler = false; |
| StreamSubscription subscription; |
| + Function _onError; |
| - MojoEventStreamListener.fromEndpoint(MojoMessagePipeEndpoint endpoint, |
| - {bool doListen: true, Function onClosed}) |
| + MojoEventStreamListener.fromEndpoint(MojoMessagePipeEndpoint endpoint) |
| : _endpoint = endpoint, |
| _eventStream = new MojoEventStream(endpoint.handle), |
| _isOpen = false { |
| - if (doListen) { |
| - listen(onClosed: onClosed); |
| - } |
| + listen(); |
| } |
| - MojoEventStreamListener.fromHandle(MojoHandle handle, {bool doListen: true, |
| - Function onClosed}) { |
| + MojoEventStreamListener.fromHandle(MojoHandle handle) { |
| _endpoint = new MojoMessagePipeEndpoint(handle); |
| _eventStream = new MojoEventStream(handle); |
| _isOpen = false; |
| - if (doListen) { |
| - listen(onClosed: onClosed); |
| - } |
| + listen(); |
| } |
| MojoEventStreamListener.unbound() |
| @@ -173,14 +168,14 @@ class MojoEventStreamListener { |
| _isOpen = false; |
| } |
| - StreamSubscription<List<int>> listen({Function onClosed}) { |
| + StreamSubscription<List<int>> listen() { |
| assert(isBound && (subscription == null)); |
| _isOpen = true; |
| subscription = _eventStream.listen((List<int> event) { |
| var signalsWatched = new MojoHandleSignals(event[0]); |
| var signalsReceived = new MojoHandleSignals(event[1]); |
| if (signalsReceived.isPeerClosed) { |
| - if (onClosed != null) onClosed(); |
| + if (onError != null) onError(); |
| close(); |
| // The peer being closed obviates any other signal we might |
| // have received since we won't be able to read or write the handle. |
| @@ -217,6 +212,21 @@ class MojoEventStreamListener { |
| void handleRead() {} |
| void handleWrite() {} |
| + Function get onError => _onError; |
| + set onError(Function f) { |
| + if (f == null) { |
| + _onError = null; |
| + } else { |
| + Function cachedOnError = _onError; |
|
hansmuller1
2015/03/05 00:35:32
Why are we accumulating onError functions here? De
zra
2015/03/05 16:39:29
I was worried about people accidentally overwritin
|
| + _onError = (() { |
| + if (cachedOnError != null) { |
| + cachedOnError(); |
| + } |
| + f(); |
| + }); |
| + } |
| + } |
| + |
| MojoMessagePipeEndpoint get endpoint => _endpoint; |
| bool get isOpen => _isOpen; |
| bool get isInHandler => _isInHandler; |