Providers pool
Connections pool for providers from @npm/ethers.
Installing
npm i @cybridge/providers-pool
Testing
npm run test
Usage
'use strict'
const { createPool } = require('../')
const ethers = require("ethers")
/**
* Init pool, with limit of 2 parallel connections
*/
const pool = createPool(ethers.providers.JsonRpcProvider, 2)
/**
* Add URLs for round robing requests
*/
pool.addUrl('https://mainnet.infura.io/...')
pool.addUrl('https://rpc.ankr.com/eth_goerli')
/**
* Get provider
*/
const provider = pool.nextProvider()
/**
* Use provider
*/
provider.getBlockNumber().then(resp => {
console.dir(resp)
/**
* Release provider
*/
pool.releaseProvider(provider)
})