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

Unified Diff: mojo/public/dart/src/event_stream.dart

Issue 982673002: Dart: Removes need to call listen(). (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Merge and Format Created 5 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/public/dart/src/codec.dart ('k') | mojo/public/dart/src/proxy.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 42391e4b30d287c7e1e9cbd104ac56d49f3e47bb..bbdb351ebbd51e6b8d2b19ed83b2e7c4c28d11c4 100644
--- a/mojo/public/dart/src/event_stream.dart
+++ b/mojo/public/dart/src/event_stream.dart
@@ -120,9 +120,7 @@ class MojoEventStream extends Stream<List<int>> {
String toString() => "$_handle";
}
-abstract class Listener {
- StreamSubscription<List<int>> listen({Function onClosed});
-}
+typedef void ErrorHandler();
class MojoEventStreamListener {
MojoMessagePipeEndpoint _endpoint;
@@ -130,25 +128,20 @@ class MojoEventStreamListener {
bool _isOpen = false;
bool _isInHandler = false;
StreamSubscription subscription;
+ ErrorHandler 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()
@@ -170,7 +163,7 @@ 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) {
@@ -190,7 +183,7 @@ class MojoEventStreamListener {
}
_isInHandler = false;
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.
« no previous file with comments | « mojo/public/dart/src/codec.dart ('k') | mojo/public/dart/src/proxy.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698