INNER CODE UNIT · TypeScript

concat

grammyjs/grammY · src/composer.ts:143

function concat<C extends Context>(
    first: MiddlewareFn<C>,
    andThen: MiddlewareFn<C>,
): MiddlewareFn<C> {
    return async (ctx, next) => {
        let nextCalled = false;
        await first(ctx, async () => {
            if (nextCalled) throw new Error("`next` already called before!");
            else nextCalled = true;
            await andThen(ctx, next);
        });
    };
}
function pass<C extends Context>(_ctx: C, next: NextFunction) {
    return next();
}

const leaf: NextFunction = () => Promise.resolve();

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…