mirror of
https://github.com/laochan-eacnet/backend.git
synced 2026-09-22 22:28:11 +03:00
35 lines
1.1 KiB
TypeScript
35 lines
1.1 KiB
TypeScript
/**
|
|
* Some predefined delay values (in milliseconds).
|
|
*/
|
|
export enum Delays {
|
|
Short = 500,
|
|
Medium = 2000,
|
|
Long = 5000,
|
|
}
|
|
|
|
/**
|
|
* Returns a Promise<string> that resolves after a given time.
|
|
*
|
|
* @param {string} name - A name.
|
|
* @param {number=} [delay=Delays.Medium] - A number of milliseconds to delay resolution of the Promise.
|
|
* @returns {Promise<string>}
|
|
*/
|
|
function delayedHello(
|
|
name: string,
|
|
delay: number = Delays.Medium,
|
|
): Promise<string> {
|
|
return new Promise((resolve: (value?: string) => void) =>
|
|
setTimeout(() => resolve(`Hello, ${name}`), delay),
|
|
);
|
|
}
|
|
|
|
// Please see the comment in the .eslintrc.json file about the suppressed rule!
|
|
// Below is an example of how to use ESLint errors suppression. You can read more
|
|
// at https://eslint.org/docs/latest/user-guide/configuring/rules#disabling-rules
|
|
|
|
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
export async function greeter(name: any) { // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
// The name parameter should be of type string. Any is used only to trigger the rule.
|
|
return await delayedHello(name, Delays.Long);
|
|
}
|