Skip to content

Reg pool connect event and checking out connections from pool #3151

Open
@deostroll

Description

@deostroll

Are there any issues with this pattern of code:

let pool = new Pool({ max: 5 });

pool.on('connect', (client) => {
	client._ready = new Promise((resolve, reject) => {
		
		client.query('SET search_path to foo, public', (err) => {
			if(err) {
				reject(err);
			} else {
				resolve();
			}
		});
		
	});
});


//...some other place

pool.getConnection(function(err, client, release) {
	if(err) {
		// error handling
	}
	
	client._ready.then(() => {
		//run some query and on success release the client back to pool
               //if errors post query execution then also release client back to pool
	}).catch(err2 => {
		//some other kind of error handling
	});
	
});

Inside getConnection() callback function, will _ready always be a promise? Can it ever become undefined? 🤔

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions