From 03f922017b1b1bfb6852723b2027d6277f3f44c8 Mon Sep 17 00:00:00 2001 From: Mihail Stoykov Date: Mon, 18 Mar 2024 10:24:19 +0200 Subject: [PATCH 1/3] Stabalize k6/experimental/timers --- types/k6/index.d.ts | 1 + types/k6/test/timers.ts | 2 +- types/k6/timers.d.ts | 47 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 types/k6/timers.d.ts diff --git a/types/k6/index.d.ts b/types/k6/index.d.ts index 294bdd6bbfe8c7..d2666f2d064643 100644 --- a/types/k6/index.d.ts +++ b/types/k6/index.d.ts @@ -36,6 +36,7 @@ import "./experimental/tracing"; import "./experimental/webcrypto"; import "./experimental/websockets"; import "./experimental/grpc"; +import "./timers"; import "./ws"; import "./net/grpc"; diff --git a/types/k6/test/timers.ts b/types/k6/test/timers.ts index 6183d425663757..2bcf3ffe89955e 100644 --- a/types/k6/test/timers.ts +++ b/types/k6/test/timers.ts @@ -1,4 +1,4 @@ -import { clearInterval, clearTimeout, setInterval, setTimeout } from "k6/experimental/timers"; +import { clearInterval, clearTimeout, setInterval, setTimeout } from "k6/timers"; // setTimeout diff --git a/types/k6/timers.d.ts b/types/k6/timers.d.ts new file mode 100644 index 00000000000000..bd95fd97aca540 --- /dev/null +++ b/types/k6/timers.d.ts @@ -0,0 +1,47 @@ +/** + * This module provides setInterval, setTimeout and co. + */ + +/** + * Set a timer which execution a function once the timer expires. + * + * @param functionRef - The function to be executed. + * @param delay - The delay in milliseconds. + * @param args - The arguments to be passed to the function. + * @returns The timer id. + */ +export function setTimeout(functionRef: (...args: any[]) => void, delay: number, ...args: any[]): TimeoutID; + +/** + * Cancels a timeout previously set with setTimeout(). + * + * @param timeoutID - The timer id to be cancelled. + */ +export function clearTimeout(timeoutID: TimeoutID): void; + +/** + * Repeatedly execute a function, with a fixed time delay between each call. + * + * @param functionRef - The function to be executed. + * @param delay - The delay in milliseconds. + * @param args - The arguments to be passed to the function. + * @returns The interval id. + */ +export function setInterval(functionRef: (...args: any[]) => void, delay: number, ...args: any[]): IntervalID; + +/** + * Cancels a interval previously set with setInterval(). + * + * @param intervalID - The interval id to be cancelled. + */ +export function clearInterval(intervalID: IntervalID): void; + +/** + * Type alias for a timer id. + */ +export type TimeoutID = number; + +/** + * Type alias for a interval id. + */ +export type IntervalID = number; From 44c7fa54e816b0fa334d57e2e2abb56e90121ba4 Mon Sep 17 00:00:00 2001 From: Mihail Stoykov <312246+mstoykov@users.noreply.github.com> Date: Mon, 18 Mar 2024 10:56:30 +0200 Subject: [PATCH 2/3] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Joan López de la Franca Beltran <5459617+joanlopez@users.noreply.github.com> --- types/k6/timers.d.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/types/k6/timers.d.ts b/types/k6/timers.d.ts index bd95fd97aca540..44a931571d5e65 100644 --- a/types/k6/timers.d.ts +++ b/types/k6/timers.d.ts @@ -3,7 +3,7 @@ */ /** - * Set a timer which execution a function once the timer expires. + * Set a timer that executes a function once the timer expires. * * @param functionRef - The function to be executed. * @param delay - The delay in milliseconds. @@ -13,7 +13,7 @@ export function setTimeout(functionRef: (...args: any[]) => void, delay: number, ...args: any[]): TimeoutID; /** - * Cancels a timeout previously set with setTimeout(). + * Cancels a timer previously set with setTimeout(). * * @param timeoutID - The timer id to be cancelled. */ @@ -30,7 +30,7 @@ export function clearTimeout(timeoutID: TimeoutID): void; export function setInterval(functionRef: (...args: any[]) => void, delay: number, ...args: any[]): IntervalID; /** - * Cancels a interval previously set with setInterval(). + * Cancels an interval previously set with setInterval(). * * @param intervalID - The interval id to be cancelled. */ From c064419ccb49ae5d5020718d441e3b3539f2ea83 Mon Sep 17 00:00:00 2001 From: Mihail Stoykov Date: Mon, 18 Mar 2024 10:57:37 +0200 Subject: [PATCH 3/3] Update experimental docs with fixes --- types/k6/experimental/timers.d.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/types/k6/experimental/timers.d.ts b/types/k6/experimental/timers.d.ts index bd95fd97aca540..44a931571d5e65 100644 --- a/types/k6/experimental/timers.d.ts +++ b/types/k6/experimental/timers.d.ts @@ -3,7 +3,7 @@ */ /** - * Set a timer which execution a function once the timer expires. + * Set a timer that executes a function once the timer expires. * * @param functionRef - The function to be executed. * @param delay - The delay in milliseconds. @@ -13,7 +13,7 @@ export function setTimeout(functionRef: (...args: any[]) => void, delay: number, ...args: any[]): TimeoutID; /** - * Cancels a timeout previously set with setTimeout(). + * Cancels a timer previously set with setTimeout(). * * @param timeoutID - The timer id to be cancelled. */ @@ -30,7 +30,7 @@ export function clearTimeout(timeoutID: TimeoutID): void; export function setInterval(functionRef: (...args: any[]) => void, delay: number, ...args: any[]): IntervalID; /** - * Cancels a interval previously set with setInterval(). + * Cancels an interval previously set with setInterval(). * * @param intervalID - The interval id to be cancelled. */