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

Side by Side Diff: lib/pool.dart

Issue 1215053004: pkg/pool: remove usage of Chain.track (Closed) Base URL: https://github.com/dart-lang/pool.git@master
Patch Set: nits Created 5 years, 5 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
« no previous file with comments | « no previous file | pubspec.yaml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 library pool; 5 library pool;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:collection'; 8 import 'dart:collection';
9 9
10 import 'package:stack_trace/stack_trace.dart'; 10 import 'package:stack_trace/stack_trace.dart';
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 _resetTimer(); 80 _resetTimer();
81 return completer.future; 81 return completer.future;
82 } 82 }
83 } 83 }
84 84
85 /// Requests a resource for the duration of [callback], which may return a 85 /// Requests a resource for the duration of [callback], which may return a
86 /// Future. 86 /// Future.
87 /// 87 ///
88 /// The return value of [callback] is piped to the returned Future. 88 /// The return value of [callback] is piped to the returned Future.
89 Future withResource(callback()) { 89 Future withResource(callback()) {
90 return request().then((resource) => 90 return request().then((resource) => new Future.sync(callback).whenComplete(r esource.release));
91 Chain.track(new Future.sync(callback)).whenComplete(resource.release));
92 } 91 }
93 92
94 /// If there are any pending requests, this will fire the oldest one. 93 /// If there are any pending requests, this will fire the oldest one.
95 void _onResourceReleased() { 94 void _onResourceReleased() {
96 _resetTimer(); 95 _resetTimer();
97 96
98 if (_requestedResources.isEmpty) { 97 if (_requestedResources.isEmpty) {
99 _allocatedResources--; 98 _allocatedResources--;
100 return; 99 return;
101 } 100 }
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 /// may be complete, but it could still emit asynchronous errors. 196 /// may be complete, but it could still emit asynchronous errors.
198 void allowRelease(onRelease()) { 197 void allowRelease(onRelease()) {
199 if (_released) { 198 if (_released) {
200 throw new StateError("A PoolResource may only be released once."); 199 throw new StateError("A PoolResource may only be released once.");
201 } 200 }
202 _released = true; 201 _released = true;
203 _pool._onResourceReleaseAllowed(onRelease); 202 _pool._onResourceReleaseAllowed(onRelease);
204 } 203 }
205 } 204 }
206 205
OLDNEW
« no previous file with comments | « no previous file | pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698