Skip to content

Commit

Permalink
fix: await cleanup in timer
Browse files Browse the repository at this point in the history
  • Loading branch information
dnalborczyk committed Oct 10, 2022
1 parent b03cf79 commit f5b8c68
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/lambda/LambdaFunctionPool.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ export default class LambdaFunctionPool {

// NOTE: don't use setInterval, as it would schedule always a new run,
// regardless of function processing time and e.g. user action (debugging)
this.#timerRef = setTimeout(() => {
this.#timerRef = setTimeout(async () => {
const cleanupWait = []

// console.log('run cleanup')
this.#pool.forEach((lambdaFunctions, functionKey) => {
lambdaFunctions.forEach((lambdaFunction) => {
Expand All @@ -35,8 +37,8 @@ export default class LambdaFunctionPool {
status === 'IDLE' &&
idleTimeInMillis >= functionCleanupIdleTimeInMillis
) {
// console.log(`removed Lambda Function ${lambdaFunction.functionName}`)
lambdaFunction.cleanup()
cleanupWait.push(lambdaFunction.cleanup())

lambdaFunctions.delete(lambdaFunction)
}
})
Expand All @@ -46,6 +48,8 @@ export default class LambdaFunctionPool {
}
})

await Promise.all(cleanupWait)

// schedule new timer
this.#startCleanTimer()
}, functionCleanupIdleTimeInMillis)
Expand Down

0 comments on commit f5b8c68

Please sign in to comment.