HDWalletProvider engine.stop()

  
p = HDWalletProvider(MNEMONIC_SYSTEM, "http://ganache:8545", 0);  
p.engine.stop();  

HDWalletProvider engine.stop() and pool

  
export function GetHdProvider(id: number, rpcurl: string) {  
  //return new HDWalletProvider(MNEMONIC_SYSTEM, url, id);  
  
  return id==0?Provider1Pool.acquire():Provider2Pool.acquire();  
}  
  
// Normal use  
const hdProvider0 = await GetHdProvider(0, providerUrl).then(function(client) {return client}).catch(function(err) {throw new HttpException(err.toString(), HttpStatus.BAD_REQUEST);});  
  
const hdProvider1 = await GetHdProvider(1, providerUrl).then(function(client) {return client}).catch(function(err) {throw new HttpException(err.toString(), HttpStatus.BAD_REQUEST);});  
  
// Normal release  
ReleaseHDProvider1(hdProvider1 );  
  
// Pool code  
const genericPool = require("generic-pool");  
  
const opts = {  
  max: 10, // maximum size of the pool  
  min: 2, // minimum size of the pool  
  idleTimeoutMillis: 30000,  
  log: true  
};  
  
const factory0 = {  // maybe different parms  
  create: function() {  
    return new HDWalletProvider(MNEMONIC_SYSTEM, RPCURL, 0);  
  },  
  destroy: function(client) {  
    client.engine.stop();  
  }  
};  
  
const factory1 = {  // maybe different parms  
  create: function() {  
    return new HDWalletProvider(MNEMONIC_SYSTEM, RPCURL, 1);  
  },  
  destroy: function(client) {  
    client.engine.stop();  
  }  
};  
  
export function ReleaseHDProvider1(client){  
  Provider1Pool.release(client);  
  console.log("Provider1Pool status: pool.size %o pool.available %o pool.pending %o", Provider1Pool.size, Provider1Pool.available, Provider1Pool.pending)  
}  
  
export function ReleaseHDProvider2(client){  
  Provider2Pool.release(client);  
  console.log("Provider2Pool status: pool.size %o pool.available %o pool.pending %o", Provider2Pool.size, Provider2Pool.available, Provider2Pool.pending)  
}  
  
const Provider1Pool = genericPool.createPool(factory0, opts);  
const Provider2Pool = genericPool.createPool(factory1, opts);