@grouparoo/core
Version:
The Grouparoo Core
44 lines (43 loc) • 1.69 kB
TypeScript
import cls from "cls-hooked";
/**
* This module is so you can delay the execution of side-effects within a transaction.
* Say your new Model() creates a task... you don't want to enqueue it until after the transaction settles.
* Use: `CLS.enqueueTaskIn(1000, taskName, args)`
* If you are in a CLS transaction, it will be run afterwards by CLSTask or CLSAction
* If you aren't in a CLS transaction, it will be run now.
*
* The more generic usage is `CLS.afterCommit(() => {})` where you can supply any async function
*
* Learn more @ https://sequelize.org/master/manual/transactions.html and https://github.com/Jeff-Lewis/cls-hooked
*/
export declare namespace CLS {
function getNamespace(): cls.Namespace;
function get(key: string): any;
function set(key: string, data: any): any;
/**
* Wrap an Async function f in such a way that all enqueued afterCommit / enqueueTasks during invocation will be run afterwords
* Returns the return value of function f
*/
interface CLSWrapMethod<T = any> {
(f: Function, options?: {
catchError?: boolean;
write?: boolean;
priority?: boolean;
}): Promise<T>;
}
const wrap: CLSWrapMethod;
function active(): boolean;
function afterCommit(f: Function): Promise<any>;
/**
* A CLS wrapper around task.enqueue
*/
function enqueueTask(taskName: string, args: {
[key: string]: any;
}, queue?: string): Promise<void>;
/**
* A CLS wrapper around task.enqueueIn
*/
function enqueueTaskIn(delay: number, taskName: string, args: {
[key: string]: any;
}, queue?: string): Promise<void>;
}