New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

resource-pool

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

resource-pool

Resource Pooling.

latest
Source
npmnpm
Version
0.1.4
Version published
Maintainers
1
Created
Source

Resource-Pool

Resource Pooling.

Install

$ npm install resource-pool

How to Use

/* 以创建 mongodb 连接池为例 */

const Pool = require('resource-pool')
const MongoClient = require('mongodb').MongoClient
const MONGO_URI = 'mongodb://localhost:27017/some-mongodb'

function createConnection () {
  return new Promise((resolve) => {
    MongoClient.connect(MONGO_URI, (err, db) => {
      if (err) throw err
      resolve(db)
    })
  })
}

function closeConnection (db) {
  db.close()
}

const pool = new Pool({
  create: createConnection,
  destroy: closeConnection
})

pool.acquire().then(({r, release}) => { // get resource from pool
  // r is the resource instance, and it is the `db` boject here for mongodb
  let col = r.collection('articles')
  col.insert({
    title: '从今天开始',
    description: '关心粮食和素材。我有一所房子,面朝大海,春暖花开。'
  })
  // return to pool
  release()
})

FAQs

Package last updated on 11 Oct 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts