"use strict";
/*
 * @adonisjs/profiler
 *
 * (c) Harminder Virk <virk@adonisjs.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.AbstractProfiler = void 0;
/**
 * Abstract class to be extended to add support for timing functions.
 */
class AbstractProfiler {
    async profileAsync(action, data, cb) {
        const profilerAction = this.getAction(action, data);
        if (typeof cb === 'function') {
            try {
                const result = await cb();
                profilerAction.end();
                return result;
            }
            catch (error) {
                profilerAction.end({ error });
                throw error;
            }
        }
        return profilerAction;
    }
    profile(action, data, cb) {
        const profilerAction = this.getAction(action, data);
        if (typeof cb === 'function') {
            try {
                const result = cb();
                profilerAction.end();
                return result;
            }
            catch (error) {
                profilerAction.end({ error });
                throw error;
            }
        }
        return profilerAction;
    }
}
exports.AbstractProfiler = AbstractProfiler;
