dart-lang / pool

A class for managing a finite pool of resources.

Home Page:https://pub.dev/packages/pool

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bad state: withResource() may not be called on a closed Pool.

xvrh opened this issue · comments

import 'dart:async';
import 'package:pool/pool.dart';

main() async {
  Pool pool = new Pool(3);

  for (int i = 0; i < 4; i++) {
    pool.withResource(() {
      print(i);
    });
  }

  await pool.close();
}

With the version 1.2.1 of pool it prints "0, 1, 2, 3"
With version 1.2.2, it fails with error

Unhandled exception:
Bad state: withResource() may not be called on a closed Pool.
#0      Pool.withResource.<withResource_async_body> (package:pool/pool.dart:111:7)
#1      Future.Future.microtask.<anonymous closure> (dart:async/future.dart:144)
#2      _microtaskLoop (dart:async/schedule_microtask.dart:41)
#3      _startMicrotaskLoop (dart:async/schedule_microtask.dart:50)
#4      _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:96)
#5      _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:149)