connection_pool 0.1.2

  • Installing
  • Versions
  • 8

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)));



  • Added changelog
  • Added release / close connection


  • Fix pubspec.yaml
  • Fix example


  • First release

Use this package as a library

1. Depend on it

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

  connection_pool: ^0.1.2

2. Install it

You can install packages from the command line:

with pub:

$ pub get

Alternatively, your editor might support pub 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
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

The package version is not analyzed, because it does not support Dart 2. Until this is resolved, the package will receive a health and maintenance score of 0.

Analysis issues and suggestions

Support Dart 2 in pubspec.yaml.

The SDK constraint in pubspec.yaml doesn't allow the Dart 2.0.0 release. For information about upgrading it to be Dart 2 compatible, please see

Maintenance issues and suggestions

Make sure dartdoc successfully runs on your package's source files. (-10 points)

Dependencies were not resolved.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.4.0 <2.0.0