Skip to content

Commit

Permalink
refactor: remove setTimeout promisify wrapper, use built-in
Browse files Browse the repository at this point in the history
  • Loading branch information
dnalborczyk committed Oct 3, 2023
1 parent b8f99fb commit 10d5f3b
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 20 deletions.
6 changes: 2 additions & 4 deletions src/lambda/LambdaFunction.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { readFile, writeFile } from 'node:fs/promises'
import { dirname, join, resolve } from 'node:path'
import process from 'node:process'
import { performance } from 'node:perf_hooks'
import { promisify } from 'node:util'
import { setTimeout } from 'node:timers/promises'
import { log } from '@serverless/utils/log.js'
import { emptyDir, ensureDir, remove } from 'fs-extra'
import jszip from 'jszip'
Expand All @@ -20,8 +20,6 @@ import { createUniqueId } from '../utils/index.js'
const { ceil } = Math
const { entries, fromEntries } = Object

const setTimeoutPromise = promisify(setTimeout)

export default class LambdaFunction {
#artifact = null

Expand Down Expand Up @@ -278,7 +276,7 @@ export default class LambdaFunction {
}

async #timeoutAndTerminate() {
await setTimeoutPromise(this.#timeout)
await setTimeout(this.#timeout)

throw new LambdaTimeoutError('[504] - Lambda timeout.')
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import assert from 'node:assert'
import { promisify } from 'node:util'
import { setTimeout } from 'node:timers/promises'
import { join } from 'desm'
import { setup, teardown } from '../../../_testHelpers/index.js'
import { BASE_URL } from '../../../config.js'

const setTimeoutPromise = promisify(setTimeout)

describe('run mode with in-process', function desc() {
beforeEach(() =>
setup({
Expand Down Expand Up @@ -43,7 +41,7 @@ describe('run mode with in-process', function desc() {
// eslint-disable-next-line no-unused-vars
for (const _ of new Array(5)) {
// eslint-disable-next-line no-await-in-loop
await setTimeoutPromise(2000)
await setTimeout(2000)
results.push(fetch(url))
}

Expand Down
6 changes: 2 additions & 4 deletions tests/lambda-run-mode/in-process/instances/src/handler.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { promisify } from 'node:util'

const setTimeoutPromise = promisify(setTimeout)
import { setTimeout } from 'node:timers/promises'

const { stringify } = JSON

Expand All @@ -9,7 +7,7 @@ let counter = 0
export async function foo() {
counter += 1

await setTimeoutPromise(1000, 'result')
await setTimeout(1000, 'result')

return {
body: stringify(counter),
Expand Down
6 changes: 2 additions & 4 deletions tests/lambda-run-mode/worker-threads/instances/src/handler.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { promisify } from 'node:util'

const setTimeoutPromise = promisify(setTimeout)
import { setTimeout } from 'node:timers/promises'

const { stringify } = JSON

Expand All @@ -9,7 +7,7 @@ let counter = 0
export async function foo() {
counter += 1

await setTimeoutPromise(1000, 'result')
await setTimeout(1000, 'result')

return {
body: stringify(counter),
Expand Down
6 changes: 2 additions & 4 deletions tests/lambda-run-mode/worker-threads/timeout/src/handler.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { promisify } from 'node:util'

const setTimeoutPromise = promisify(setTimeout)
import { setTimeout } from 'node:timers/promises'

const { stringify } = JSON

Expand All @@ -9,7 +7,7 @@ let counter = 0
export async function foo(event, context) {
counter += 1

await setTimeoutPromise(1000, 'result')
await setTimeout(1000, 'result')

return {
body: stringify({
Expand Down

0 comments on commit 10d5f3b

Please sign in to comment.