# callbackWaitsForEmptyEventLoop and cached connections/pools?

**URL:** <https://forum.serverless.com/t/callbackwaitsforemptyeventloop-and-cached-connections-pools/4362>\
**Category:** Serverless Architectures\
**Created:** [April 27, 2018, 1:34am UTC](https://forum.serverless.com/t/callbackwaitsforemptyeventloop-and-cached-connections-pools/4362 "2018-04-27T01:34:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![walshe](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/walshe/32/1032_2.png) [@walshe](https://forum.serverless.com/u/walshe)\
**Post date:** [April 27, 2018, 1:34am UTC](https://forum.serverless.com/t/callbackwaitsforemptyeventloop-and-cached-connections-pools/4362/1 "2018-04-27T01:34:53Z")

</div>

I read a few articles on calling rds from lambdas and how to use ‘context.callbackWaitsForEmptyEventLoop = false’ in order to try to hand on to cached connections in warm lambdas.

I have read some that advise to use a connection pool of size 1, but is there even any point in using a conenciton pool. Wouldn’t a simple connection like below serve the exact same purpose ?

```
import * as dynamoDbLib from "../../libs/dynamodb-lib";
import { success, failure } from "../../libs/response-lib";

var mysql = require('mysql2/promise');

let cachedConnection = null

export const main = async (event, context, callback) => {

    console.log('event', JSON.stringify(event))
    try {

        context.callbackWaitsForEmptyEventLoop = false;

        if (cachedConnection === null) {
            console.log('creating connection')
            cachedConnection = await mysql.createConnection({
                host: "dev.xxxx.rds.amazonaws.com",
                user: "xxxxxxxx",
                password: "xxxxxxxxxxx",
                database: "orders-service",
            });
            console.log('connection created')
        } else {
            console.log('using cached connection')
        }

        const [rows, fields] = await cachedConnection.query('insert into test set ?', { orderId: event.id});

        callback(null, success(rows));

    } catch (error) {
        console.log(error)
        callback(null, failure({ status: false, error: error }));
    }
};
```

---

<div class="post-metadata">

**Author:** ![joelw](https://avatars.discourse-cdn.com/v4/letter/j/e0b2c6/32.png) [@joelw](https://forum.serverless.com/u/joelw)\
**Post date:** [March 11, 2021, 10:22pm UTC](https://forum.serverless.com/t/callbackwaitsforemptyeventloop-and-cached-connections-pools/4362/2 "2021-03-11T22:22:53Z")

</div>

I was wondering the same. Any further insight on this?
