Skip to content

Commit

Permalink
Latest lints, test wasm on dev channel (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevmoo committed Feb 28, 2024
1 parent 782da82 commit c118f69
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 61 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,6 @@ jobs:
- name: Run Chrome tests
run: dart test --platform chrome
if: always() && steps.install.outcome == 'success'
- name: Run Chrome tests - wasm
run: dart test --platform chrome -c dart2wasm
if: always() && steps.install.outcome == 'success' && matrix.sdk == 'dev'
35 changes: 19 additions & 16 deletions lib/pool.dart
Original file line number Diff line number Diff line change
Expand Up @@ -239,23 +239,26 @@ class Pool {
/// an error, the returned future completes with that error.
///
/// This may be called more than once; it returns the same [Future] each time.
Future close() => _closeMemo.runOnce(() {
if (_closeGroup != null) return _closeGroup!.future;
Future close() => _closeMemo.runOnce(_close);

_resetTimer();
Future<void> _close() {
if (_closeGroup != null) return _closeGroup!.future;

_closeGroup = FutureGroup();
for (var callback in _onReleaseCallbacks) {
_closeGroup!.add(Future.sync(callback));
}
_resetTimer();

_allocatedResources -= _onReleaseCallbacks.length;
_onReleaseCallbacks.clear();
_closeGroup = FutureGroup();
for (var callback in _onReleaseCallbacks) {
_closeGroup!.add(Future.sync(callback));
}

_allocatedResources -= _onReleaseCallbacks.length;
_onReleaseCallbacks.clear();

if (_allocatedResources == 0) _closeGroup!.close();
return _closeGroup!.future;
}

if (_allocatedResources == 0) _closeGroup!.close();
return _closeGroup!.future;
});
final _closeMemo = AsyncMemoizer();
final _closeMemo = AsyncMemoizer<void>();

/// If there are any pending requests, this will fire the oldest one.
void _onResourceReleased() {
Expand All @@ -272,7 +275,7 @@ class Pool {

/// If there are any pending requests, this will fire the oldest one after
/// running [onRelease].
void _onResourceReleaseAllowed(Function() onRelease) {
void _onResourceReleaseAllowed(void Function() onRelease) {
_resetTimer();

if (_requestedResources.isNotEmpty) {
Expand All @@ -294,7 +297,7 @@ class Pool {
///
/// Futures returned by [_runOnRelease] always complete in the order they were
/// created, even if earlier [onRelease] callbacks take longer to run.
Future<PoolResource> _runOnRelease(Function() onRelease) {
Future<PoolResource> _runOnRelease(void Function() onRelease) {
Future.sync(onRelease).then((value) {
_onReleaseCompleters.removeFirst().complete(PoolResource._(this));
}).catchError((Object error, StackTrace stackTrace) {
Expand Down Expand Up @@ -367,7 +370,7 @@ class PoolResource {
/// This is useful when a resource's main function is complete, but it may
/// produce additional information later on. For example, an isolate's task
/// may be complete, but it could still emit asynchronous errors.
void allowRelease(Function() onRelease) {
void allowRelease(FutureOr<void> Function() onRelease) {
if (_released) {
throw StateError('A PoolResource may only be released once.');
}
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ dependencies:
stack_trace: ^1.10.0

dev_dependencies:
dart_flutter_team_lints: ^1.0.0
dart_flutter_team_lints: ^2.0.0
fake_async: ^1.2.0
test: ^1.16.0
Loading

0 comments on commit c118f69

Please sign in to comment.