Skip to main content
Module

x/run_exclusive/mod.ts>buildCb

⚡🔒 Wait queue for function execution 🔒 ⚡
Go to Latest
function buildCb
import { buildCb } from "https://deno.land/x/run_exclusive@v2.2.18/mod.ts";

(Read all before using)

The pending of 'build' for creating run exclusive functions that complete via calling a callback function. (Instead of returning a promise).

The only valid reason to use this instead of build() is to be able to retrieve the result and/or release the lock synchronously when it's possible.

If you want the callback to be optional it is possible to define the function as such:
const myRunExclusiveFunction = buildCb((callback?)=> { ... });
Anyway you must call it every time and assume it has been defined: callback!(...).

To see if the user has actually provided a callback you can access the hidden property callback.hasCallback.

WARNING: You must also make sure, if you use an optional callback that the argument before it cannot be a function.
Be aware that the compiler won't warn you against it.
Example: (getLetter:()=> string, callback?:(res:string)=> void)=>{..}
is NOT a valid function to pass to buildCb()

WARNING: the source function should NEVER throw exception!

Type Parameters

T extends (...input: any[]) => void

Type Parameters

T extends (...input: any[]) => void

Parameters

groupRef: GroupRef
fun: T