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

Unified Diff: runtime/bin/chunked_stream.dart

Issue 8839012: Only schedule one data callback at the time for chunked input stream (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 9 years 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/chunked_stream.dart
diff --git a/runtime/bin/chunked_stream.dart b/runtime/bin/chunked_stream.dart
index 26602b75db75e532757af5225cd111cc43fe4625..b0e7fcbb6f9828b4c0e670912913fc6986a73af5 100644
--- a/runtime/bin/chunked_stream.dart
+++ b/runtime/bin/chunked_stream.dart
@@ -89,6 +89,7 @@ class _ChunkedInputStream implements ChunkedInputStream {
// TODO(sgjesse): Find a better way of scheduling callbacks from
// the event loop.
void issueDataCallback(Timer timer) {
+ _scheduledDataCallback = null;
if (_clientDataHandler !== null) {
_clientDataHandler();
_checkScheduleCallback();
@@ -96,6 +97,7 @@ class _ChunkedInputStream implements ChunkedInputStream {
}
void issueCloseCallback(Timer timer) {
+ _scheduledCloseCallback = null;
if (!_closed) {
if (_clientCloseHandler !== null) _clientCloseHandler();
_closed = true;
@@ -105,13 +107,17 @@ class _ChunkedInputStream implements ChunkedInputStream {
// Schedule data callback if enough data in buffer.
if ((_bufferList.length >=_chunkSize ||
(_bufferList.length > 0 && _inputClosed)) &&
- _clientDataHandler !== null) {
- new Timer(issueDataCallback, 0, false);
+ _clientDataHandler !== null &&
+ _scheduledDataCallback == null) {
+ _scheduledDataCallback = new Timer(issueDataCallback, 0, false);
}
// Schedule close callback if no more data and input is closed.
- if (_bufferList.length == 0 && _inputClosed && !_closed) {
- new Timer(issueCloseCallback, 0, false);
+ if (_bufferList.length == 0 &&
+ _inputClosed &&
+ !_closed &&
+ _scheduledCloseCallback == null) {
+ _scheduledCloseCallback = new Timer(issueCloseCallback, 0, false);
}
}
@@ -120,6 +126,8 @@ class _ChunkedInputStream implements ChunkedInputStream {
int _chunkSize;
bool _inputClosed = false; // Is the underlying input stream closed?
bool _closed = false; // Has the close handler been called?.
- var _clientDataHandler;
- var _clientCloseHandler;
+ Timer _scheduledDataCallback;
+ Timer _scheduledCloseCallback;
+ Function _clientDataHandler;
+ Function _clientCloseHandler;
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698