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

Unified Diff: runtime/bin/file_impl.dart

Issue 10832188: Add an OutputStream.closed getter. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Code review changes 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « compiler/javatests/com/google/dart/compiler/parser/StringBuffer.dart ('k') | runtime/bin/http_impl.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/file_impl.dart
diff --git a/runtime/bin/file_impl.dart b/runtime/bin/file_impl.dart
index e1ff548fb669cfe7ba00be357490453da5ea5226..9b14716e92e25aaa911e56e31784a39a9a4cf135 100644
--- a/runtime/bin/file_impl.dart
+++ b/runtime/bin/file_impl.dart
@@ -217,22 +217,23 @@ class _FileOutputStream extends _BaseOutputStream implements OutputStream {
void close() {
+ _streamMarkedClosed = true;
if (_file == null) {
_pendingOperations.add(_PendingOperation.CLOSE);
- } else if (!_streamMarkedClosed) {
+ } else if (!_closeCallbackScheduled) {
_file.close().then((ignore) {
if (_onClosed != null) _onClosed();
});
- _streamMarkedClosed = true;
+ _closeCallbackScheduled = true;
}
}
void set onNoPendingWrites(void callback()) {
_onNoPendingWrites = callback;
- if (((_pendingOperations == null) || (_pendingOperations.length == 0)) &&
- (outstandingWrites == 0) &&
+ if ((_pendingOperations == null || _pendingOperations.length == 0) &&
+ outstandingWrites == 0 &&
!_streamMarkedClosed &&
- (_onNoPendingWrites != null)) {
+ _onNoPendingWrites != null) {
new Timer(0, (t) {
if (_onNoPendingWrites != null) {
_onNoPendingWrites();
@@ -266,9 +267,9 @@ class _FileOutputStream extends _BaseOutputStream implements OutputStream {
var writeListFuture = _file.writeList(buffer, offset, len);
writeListFuture.then((ignore) {
outstandingWrites--;
- if ((outstandingWrites == 0) &&
+ if (outstandingWrites == 0 &&
!_streamMarkedClosed &&
- (_onNoPendingWrites != null)) {
+ _onNoPendingWrites != null) {
_onNoPendingWrites();
}
});
@@ -279,15 +280,17 @@ class _FileOutputStream extends _BaseOutputStream implements OutputStream {
});
}
+ bool get closed() => _streamMarkedClosed;
+
RandomAccessFile _file;
// When this is set to true the stream is marked closed. When a
// stream is marked closed no more data can be written.
bool _streamMarkedClosed = false;
- // When this is set to true the close callback has been called and
- // the stream is fully closed.
- bool _closeCallbackCalled = false;
+ // When this is set to true, the close callback has been scheduled and the
+ // stream will be fully closed once it's called.
+ bool _closeCallbackScheduled = false;
// Number of writes that have not yet completed.
int outstandingWrites = 0;
« no previous file with comments | « compiler/javatests/com/google/dart/compiler/parser/StringBuffer.dart ('k') | runtime/bin/http_impl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698