Skip to content

Class: UtilsFunction ​

Utilities around functions: detecting asynchronous functions and delaying via a promise.

Remarks ​

Accessible everywhere via k.Utils.Function. All methods are static. The wait method is also exposed globally as wait.

Example ​

ts
await k.Utils.Function.wait(1000); // pause for one second

Constructors ​

Constructor ​

ts
new UtilsFunction(): UtilsFunction;

Returns ​

UtilsFunction

Methods ​

isAsync() ​

ts
static isAsync(func): boolean;

Indicates whether a function is asynchronous (declared with async).

Parameters ​

func ​

(...args) => any

The function to test.

Returns ​

boolean

true if func is an AsyncFunction, false otherwise.

Example ​

ts
k.Utils.Function.isAsync(async () => {}); // true
k.Utils.Function.isAsync(() => {});       // false

wait() ​

ts
static wait(time): Promise<void>;

Returns a promise resolved after the given delay — handy for pausing within an async/await context.

Parameters ​

time ​

number

Wait time in milliseconds.

Returns ​

Promise<void>

A promise resolved once the delay has elapsed.

Example ​

ts
await k.Utils.Function.wait(500); // wait 500 ms
// equivalent to the global shortcut:
await wait(500);