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

Unified Diff: packages/pool/lib/pool.dart

Issue 1521693002: Roll Observatory deps (charted -> ^0.3.0) (Closed) Base URL: https://chromium.googlesource.com/external/github.com/dart-lang/observatory_pub_packages.git@master
Patch Set: Created 5 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 | « packages/pool/CHANGELOG.md ('k') | packages/pool/pubspec.yaml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: packages/pool/lib/pool.dart
diff --git a/packages/pool/lib/pool.dart b/packages/pool/lib/pool.dart
index 59b949e0eef0da58ef4d49844e205a46c67dc325..ef38614184badf457535678f6c00cc4e8f7fdc3b 100644
--- a/packages/pool/lib/pool.dart
+++ b/packages/pool/lib/pool.dart
@@ -46,12 +46,14 @@ class Pool {
/// The timeout timer.
///
- /// If [_timeout] isn't null, this timer is set as soon as the resource limit
- /// is reached and is reset every time an resource is released or a new
- /// resource is requested. If it fires, that indicates that the caller became
- /// deadlocked, likely due to files waiting for additional files to be read
- /// before they could be closed.
- Timer _timer;
+ /// This timer is canceled as long as the pool is below the resource limit.
+ /// It's reset once the resource limit is reached and again every time an
+ /// resource is released or a new resource is requested. If it fires, that
+ /// indicates that the caller became deadlocked, likely due to files waiting
+ /// for additional files to be read before they could be closed.
+ ///
+ /// This is `null` if this pool shouldn't time out.
+ RestartableTimer _timer;
/// The amount of time to wait before timing out the pending resources.
final Duration _timeout;
@@ -72,7 +74,13 @@ class Pool {
/// all pending [request] futures will throw a [TimeoutException]. This is
/// intended to avoid deadlocks.
Pool(this._maxAllocatedResources, {Duration timeout})
- : _timeout = timeout;
+ : _timeout = timeout {
+ if (timeout != null) {
+ // Start the timer canceled since we only want to start counting down once
+ // we've run out of available resources.
+ _timer = new RestartableTimer(timeout, _onTimeout)..cancel();
+ }
+ }
/// Request a [PoolResource].
///
@@ -190,11 +198,12 @@ class Pool {
/// A resource has been requested, allocated, or released.
void _resetTimer() {
- if (_timer != null) _timer.cancel();
- if (_timeout == null || _requestedResources.isEmpty) {
- _timer = null;
+ if (_timer == null) return;
+
+ if (_requestedResources.isEmpty) {
+ _timer.cancel();
} else {
- _timer = new Timer(_timeout, _onTimeout);
+ _timer.reset();
}
}
« no previous file with comments | « packages/pool/CHANGELOG.md ('k') | packages/pool/pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698