Skip to main content

@rbxts/rlog > withLogContextAsync

withLogContextAsync() function

Wraps around an async callback, automatically creating and managing the lifecycle for a LogContext.

Signature:

export declare function withLogContextAsync<R = void>(callback: ContextCallback<Promise<R>>): Promise<R>;

Parameters

Parameter

Type

Description

callback

ContextCallback<Promise<R>>

ContextCallback scope to run and provide the context for.

Returns:

Promise<R>

Remarks

Will call stop on the created context when the executed scope is finished- regardless if the promise was cancelled or threw an error.

Any value returned from the callback will also be propagated appropriately.

Example

remotes.buyPet.onRequest((player: Player, pet: PetId) =>
// automatically starts and stops the context
withLogContextAsync(async (context) => {
return buyPet(context, player.UserId, pet);
}),
);