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

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

Issue 968243003: Dart: Adds optional named arguments for creating bindings. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Format Created 5 years, 10 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/application_connection.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 8f022acc93ffbb4b1b18f6d580b64cf15fae348e..9c8321709332fe05ab77edf1ca35dabf13b2dba9 100644
--- a/mojo/public/dart/src/event_stream.dart
+++ b/mojo/public/dart/src/event_stream.dart
@@ -132,16 +132,26 @@ class MojoEventStreamListener {
MojoEventStream _eventStream;
bool _isOpen = false;
bool _isInHandler = false;
+ StreamSubscription subscription;
- MojoEventStreamListener(MojoMessagePipeEndpoint endpoint)
+ MojoEventStreamListener.fromEndpoint(MojoMessagePipeEndpoint endpoint,
+ {bool doListen: true, Function onClosed})
: _endpoint = endpoint,
_eventStream = new MojoEventStream(endpoint.handle),
- _isOpen = false;
+ _isOpen = false {
+ if (doListen) {
+ listen(onClosed: onClosed);
+ }
+ }
- MojoEventStreamListener.fromHandle(MojoHandle handle) {
+ MojoEventStreamListener.fromHandle(MojoHandle handle, {bool doListen: true,
+ Function onClosed}) {
_endpoint = new MojoMessagePipeEndpoint(handle);
_eventStream = new MojoEventStream(handle);
_isOpen = false;
+ if (doListen) {
+ listen(onClosed: onClosed);
+ }
}
MojoEventStreamListener.unbound()
@@ -164,8 +174,9 @@ class MojoEventStreamListener {
}
StreamSubscription<List<int>> listen({Function onClosed}) {
+ assert(isBound && (subscription == null));
_isOpen = true;
- return _eventStream.listen((List<int> event) {
+ subscription = _eventStream.listen((List<int> event) {
var signalsWatched = new MojoHandleSignals(event[0]);
var signalsReceived = new MojoHandleSignals(event[1]);
if (signalsReceived.isPeerClosed) {
@@ -190,11 +201,13 @@ class MojoEventStreamListener {
}
_isInHandler = false;
}, onDone: close);
+ return subscription;
}
void close() {
_isOpen = false;
_endpoint = null;
+ subscription = null;
if (_eventStream != null) {
_eventStream.close();
_eventStream = null;
« no previous file with comments | « mojo/public/dart/src/application_connection.dart ('k') | mojo/public/dart/src/proxy.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698