serverless-offline 11.1.0 → 11.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "dedicatedTo": "Blue, a great migrating bird.",
3
3
  "name": "serverless-offline",
4
- "version": "11.1.0",
4
+ "version": "11.1.1",
5
5
  "description": "Emulate AWS λ and API Gateway locally when developing your Serverless project",
6
6
  "license": "MIT",
7
7
  "exports": {
@@ -25,9 +25,11 @@ export default class LambdaFunctionPool {
25
25
 
26
26
  // NOTE: don't use setInterval, as it would schedule always a new run,
27
27
  // regardless of function processing time and e.g. user action (debugging)
28
- this.#timerRef = setTimeout(() => {
28
+ this.#timerRef = setTimeout(async () => {
29
+ const cleanupWait = []
30
+
29
31
  // console.log('run cleanup')
30
- this.#pool.forEach((lambdaFunctions) => {
32
+ this.#pool.forEach((lambdaFunctions, functionKey) => {
31
33
  lambdaFunctions.forEach((lambdaFunction) => {
32
34
  const { idleTimeInMillis, status } = lambdaFunction
33
35
 
@@ -35,37 +37,43 @@ export default class LambdaFunctionPool {
35
37
  status === 'IDLE' &&
36
38
  idleTimeInMillis >= functionCleanupIdleTimeInMillis
37
39
  ) {
38
- // console.log(`removed Lambda Function ${lambdaFunction.functionName}`)
39
- lambdaFunction.cleanup()
40
+ cleanupWait.push(lambdaFunction.cleanup())
41
+
40
42
  lambdaFunctions.delete(lambdaFunction)
41
43
  }
42
44
  })
45
+
46
+ if (lambdaFunctions.size === 0) {
47
+ this.#pool.delete(functionKey)
48
+ }
43
49
  })
44
50
 
51
+ await Promise.all(cleanupWait)
52
+
45
53
  // schedule new timer
46
54
  this.#startCleanTimer()
47
55
  }, functionCleanupIdleTimeInMillis)
48
56
  }
49
57
 
50
- #cleanupPool() {
51
- const wait = []
58
+ async #cleanupPool() {
59
+ const cleanupWait = []
52
60
 
53
61
  this.#pool.forEach((lambdaFunctions) => {
54
62
  lambdaFunctions.forEach((lambdaFunction) => {
55
- // collect promises
56
- wait.push(lambdaFunction.cleanup())
57
- lambdaFunctions.delete(lambdaFunction)
63
+ cleanupWait.push(lambdaFunction.cleanup())
58
64
  })
59
65
  })
60
66
 
61
- return Promise.all(wait)
67
+ await Promise.all(cleanupWait)
68
+
69
+ this.#pool.clear()
62
70
  }
63
71
 
64
72
  // TODO make sure to call this
65
73
  async cleanup() {
66
74
  clearTimeout(this.#timerRef)
67
75
 
68
- return this.#cleanupPool()
76
+ await this.#cleanupPool()
69
77
  }
70
78
 
71
79
  get(functionKey, functionDefinition) {