connection_pool 0.1.1

  • Installing
  • Versions
  • 67

Connection Pool

Build Status Pub version

A very simple generic connection pool.

Example: How to build a MongoDB connection pool, and use it in a Redstone.dart app

import 'package:redstone/server.dart' as app;
import 'package:connection_pool/connection_pool.dart';
import 'package:mongo_dart/mongo_dart.dart';

 * A MongoDB connection pool
class MongoDbPool extends ConnectionPool<Db> {

  String uri;

  MongoDbPool(String this.uri, int poolSize) : super(poolSize);

  void closeConnection(Db conn) {

  Future<Db> openNewConnection() {
    var conn = new Db(uri);
    return => conn);

 * Retrieve and release a connection from the pool.
dbInterceptor(MongoDbPool pool) {

  //get a connection
  pool.getConnection().then((managedConnection) {

    //save the connection in the attributes map
    app.request.attributes["conn"] = managedConnection.conn; {
      if (app.chain.error is ConnectionException) {
        //if a connection is lost, mark it as invalid, so the pool can reopen it
        //in the next request
        pool.releaseConnection(managedConnection, markAsInvalid: true);
      } else {
        //release the connection


//To use a connection, just retrieve it from the attributes map
service(@app.Attr() Db conn) {

main() {


  //create a connection pool
  var mongodbUri = "mongodb://localhost/database";
  var poolSize = 3;

  app.addModule(new Module()
    ..bind(MongoDbPool, toValue: new MongoDbPool(mongoDbUri, poolSize)));



  • Fix pubspec.yaml
  • Fix example


  • First release

1. Depend on it

Add this to your package's pubspec.yaml file:

  connection_pool: "^0.1.1"

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter packages get

Alternatively, your editor might support pub get or packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:connection_pool/connection_pool.dart';
Version Uploaded Documentation Archive
0.1.2 Jul 30, 2016 Go to the documentation of connection_pool 0.1.2 Download connection_pool 0.1.2 archive
0.1.1 Jul 30, 2016 Go to the documentation of connection_pool 0.1.1 Download connection_pool 0.1.1 archive
0.1.0+2 May 31, 2014 Go to the documentation of connection_pool 0.1.0+2 Download connection_pool 0.1.0+2 archive
0.1.0+1 May 31, 2014 Go to the documentation of connection_pool 0.1.0+1 Download connection_pool 0.1.0+1 archive
0.1.0 May 31, 2014 Go to the documentation of connection_pool 0.1.0 Download connection_pool 0.1.0 archive


We analyzed this package on Mar 5, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0-dev.31.0
  • pana: 0.10.3


Describes how popular the package is relative to other packages. [more]
61 / 100
Code health derived from static analysis. [more]
94 / 100
Reflects how tidy and up-to-date the package is. [more]
40 / 100
Overall score:
Weighted score of the above. [more]
Learn more about scoring.


Detected platforms: Flutter, web, other

No platform restriction found in primary library package:connection_pool/connection_pool.dart.


  • Fix issues reported by dartanalyzer or dartfmt.

    dartanalyzer or dartfmt reported 2 warnings.

    Strong-mode analysis of lib/connection_pool.dart gave the following warning:

    line: 55 col: 35
    A function of type '(T) → void' can't be assigned to a location of type '(dynamic) → void'.

  • The description is too short.

    Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

  • Package is pre-v1 release.

    While there is nothing inherently wrong with versions of 0.*.*, it usually means that the author is still experimenting with the general direction API.

  • Maintain an example.

    Create a short demo in the example/ directory to show how to use this package. Common file name patterns include: main.dart, example.dart or you could also use connection_pool.dart.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.4.0 <2.0.0
Dev dependencies
test >=0.12.0 <0.13.0