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

Side by Side Diff: runtime/bin/list_stream_impl.dart

Issue 10832188: Add an OutputStream.closed getter. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 4 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 /** 5 /**
6 * Default implementation of [ListInputStream]. 6 * Default implementation of [ListInputStream].
7 */ 7 */
8 class _ListInputStream extends _BaseDataInputStream implements ListInputStream { 8 class _ListInputStream extends _BaseDataInputStream implements ListInputStream {
9 _ListInputStream() : _bufferList = new _BufferList(); 9 _ListInputStream() : _bufferList = new _BufferList();
10 10
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 copyBuffer: false); 64 copyBuffer: false);
65 } 65 }
66 66
67 void flush() { 67 void flush() {
68 // Nothing to do on a list output stream. 68 // Nothing to do on a list output stream.
69 } 69 }
70 70
71 void close() { 71 void close() {
72 if (_streamMarkedClosed) throw new StreamException.streamClosed(); 72 if (_streamMarkedClosed) throw new StreamException.streamClosed();
73 _streamMarkedClosed = true; 73 _streamMarkedClosed = true;
74 _checkScheduleCallbacks();
74 } 75 }
75 76
76 void destroy() { 77 void destroy() {
77 close(); 78 close();
78 } 79 }
79 80
80 void set onData(void callback()) { 81 void set onData(void callback()) {
81 _clientDataHandler = callback; 82 _clientDataHandler = callback;
82 _checkScheduleCallbacks(); 83 _checkScheduleCallbacks();
83 } 84 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 if (_clientCloseHandler !== null) _clientCloseHandler(); 119 if (_clientCloseHandler !== null) _clientCloseHandler();
119 } 120 }
120 121
121 // Schedule no pending callback if there is a callback set as this 122 // Schedule no pending callback if there is a callback set as this
122 // output stream does not wait for any transmission. Schedule 123 // output stream does not wait for any transmission. Schedule
123 // close callback once when the stream is closed. Only schedule a 124 // close callback once when the stream is closed. Only schedule a
124 // new callback if the previous one has actually been called. 125 // new callback if the previous one has actually been called.
125 if (_closeCallbackCalled) return; 126 if (_closeCallbackCalled) return;
126 127
127 if (!_streamMarkedClosed) { 128 if (!_streamMarkedClosed) {
128 if (!_bufferList.isEmpty() && 129 if (!_bufferList.isEmpty() &&
Bill Hesse 2012/08/08 14:21:11 I don't like the idea that we aren't sending onDat
129 _clientDataHandler != null && 130 _clientDataHandler != null &&
130 _scheduledDataCallback == null) { 131 _scheduledDataCallback == null) {
131 _scheduledDataCallback = new Timer(0, issueDataCallback); 132 _scheduledDataCallback = new Timer(0, issueDataCallback);
132 } 133 }
133 134
134 if (_clientNoPendingWriteHandler != null && 135 if (_clientNoPendingWriteHandler != null &&
135 _scheduledNoPendingWriteCallback == null && 136 _scheduledNoPendingWriteCallback == null &&
136 _scheduledDataCallback == null) { 137 _scheduledDataCallback == null) {
137 _scheduledNoPendingWriteCallback = 138 _scheduledNoPendingWriteCallback =
138 new Timer(0, issueNoPendingWriteCallback); 139 new Timer(0, issueNoPendingWriteCallback);
139 } 140 }
140 141
141 } else if (_clientCloseHandler != null) { 142 } else if (_clientCloseHandler != null) {
142 _scheduledCloseCallback = new Timer(0, issueCloseCallback); 143 _scheduledCloseCallback = new Timer(0, issueCloseCallback);
143 _closeCallbackCalled = true; 144 _closeCallbackCalled = true;
144 } 145 }
145 } 146 }
146 147
148 bool get closed() => _streamMarkedClosed;
149
147 _BufferList _bufferList; 150 _BufferList _bufferList;
148 bool _streamMarkedClosed = false; 151 bool _streamMarkedClosed = false;
149 bool _closeCallbackCalled = false; 152 bool _closeCallbackCalled = false;
150 Timer _scheduledDataCallback; 153 Timer _scheduledDataCallback;
151 Timer _scheduledNoPendingWriteCallback; 154 Timer _scheduledNoPendingWriteCallback;
152 Timer _scheduledCloseCallback; 155 Timer _scheduledCloseCallback;
153 Function _clientDataHandler; 156 Function _clientDataHandler;
154 Function _clientNoPendingWriteHandler; 157 Function _clientNoPendingWriteHandler;
155 Function _clientCloseHandler; 158 Function _clientCloseHandler;
156 } 159 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698